Hi,
I build a base class to read and write private fields of sub-classes,
but bursts IllegalAccessException.
public class BaseClass{
public void read(){
//reflection code
}
public void write(){
// also reflection code
}
}
public class SubClass extends BaseClass{
private String name;
//other methods
}
How can I access the private fields, such as name in SubClass inside
BaseClass?
fsa71@mail.ru - 01 Nov 2005 08:05 GMT
If I understand your question, I think you should create get/set
methods in your BaseClass to access this fields.
-------------------
http://www.excelsior-usa.com/jet.html
JVM based on Ahead-of-Time compilation
Chris Uppal - 01 Nov 2005 09:09 GMT
moopT wrote:
> I build a base class to read and write private fields of sub-classes,
> but bursts IllegalAccessException.
>
> public class BaseClass{
> public void read(){
> //reflection code
Why are you using reflection to access nested classes ? There can't be any
need for it that I can imagine.
If you are not using reflection to do so, then I think you must be doing
something wrong (that is not visible in your example) since an outer class does
have access to nested classes private members.
-- chris