|
-
May 3rd, 2000, 07:46 AM
#1
Accessing Private Fields
I like to write a library for serializing an object into XML. For this I need to access (read & write)
private variables of a subclass (the objects has to be derived from my base class). Is there a possibility
to achieve this with reflection? Or is there an other solution for my problem?
Thanks a lot for answering my question!
-
May 3rd, 2000, 07:57 PM
#2
Re: Accessing Private Fields
You may consider the method getDeclaredFields() in the class java.lang.Class. It return the fields
in the specified class. I adopt some words in the document :
Returns an array of Field objects reflecting all the fields declared by the class or interface
represented by this Class object. This includes public, protected, default (package) access,
and private fields, but excludes inherited fields.
So I guess that you might have to cast the base class to the subclass and get the field in the subclass.
I never try it. This is just the suggestion.
good luck,
Alfred Wu
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|