Re: General problem mapping objects to data and vice versa

Peter Seibel <peter@javamonkey.com>
14 Mar 2003 11:23:40 -0500

          From comp.compilers

Related articles
General problem mapping objects to data and vice versa tabbydan@myway.com (2003-02-06)
Re: General problem mapping objects to data and vice versa bobduff@shell01.TheWorld.com (Robert A Duff) (2003-02-11)
Re: General problem mapping objects to data and vice versa peter@javamonkey.com (Peter Seibel) (2003-02-11)
Re: General problem mapping objects to data and vice versa jstracke@centive.com (John Stracke) (2003-03-09)
Re: General problem mapping objects to data and vice versa peter@javamonkey.com (Peter Seibel) (2003-03-14)
| List of all articles for this month |

From: Peter Seibel <peter@javamonkey.com>
Newsgroups: comp.compilers
Date: 14 Mar 2003 11:23:40 -0500
Organization: Prodigy Internet http://www.prodigy.com
References: 03-02-034 03-02-063 03-03-032
Keywords: Java, design
Posted-Date: 14 Mar 2003 11:23:40 EST

John Stracke <jstracke@centive.com> writes:


> Peter Seibel wrote:
> > tabbydan@myway.com (tabbydan) writes:
>
> > For this task, the information you need (existance of fields and
> > methods) might be more readily at hand in the .class file; they're
> > pretty easy to parse.
>
> You don't need to parse the classfiles yourself; you can use Java's
> introspection techniques. See the javadoc for java.lang.Class and
> java.lang.reflect.


Yeah. Though you need to be careful with reflection--loading a class
(in order to reflect on it) causes the class's static initializer to
run. Which usually isn't a problem. But I've worked on systems where
my reflection-based code analyzer would never exit because some class
I loaded had a static initiazizer that spun up a non-daemon thread.
That's almost certainly bad form but there's not a lot you can do
about it. Also there's information you can get from the .class files
that you can't get from reflection, such as what methods in other
classes are called. (I forget now what the OP was looking for.)


You can also run into problems reliably loading the classes you want
if you have an app that makes any kind of complex use of classloaders,
etc. Whereas with a load the file and parse it tool you know exactly
what's going on. But, as always, YMMV.


-Peter


--
Peter Seibel peter@javamonkey.com


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.