Re: Interrogating an abstract class

[email protected] Wed, 31 Aug 2005 16:16:21 -0400
Newsgroups gmane.comp.jakarta.bcel.user
Message-ID <[email protected]>
You would have to find the default constructor "<init>" and look for stores into
the member you are interested in, and find the LDC that occurs just before it.
From there you can look up the value in the constant pool. Not an easy chore in
the general sense.

Quoting Martin Cooper <[email protected]>:

> Say I have an abstract class as follows:
> 
> public abstract class Foo {
> String myField = "DefaultValue";
> }
> 
> Note that the field is not static. How can I obtain the default value of the
> 
> field, namely "DefaultValue", without having a concrete class that I can 
> instantiate?
> 
> Using plain vanilla reflection, there doesn't appear to be a way, since the 
> only way to get the value of a non-static field is to have an instance of 
> the class. So I was hoping there might be a way to do this with BCEL, but I 
> couldn't find anything there either.
> 
> Anyone have any ideas?
> 
> --
> Martin Cooper
>