You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bcel-user@jakarta.apache.org by Martin Cooper <mf...@gmail.com> on 2005/08/31 20:03:44 UTC
Interrogating an abstract class
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
Re: Interrogating an abstract class
Posted by db...@qis.net.
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 <mf...@gmail.com>:
> 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
>
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org