Reflection

G

grz01

Hi,

Working, with Reflection, I find the methods

Class.getFields():
=> returns "all the accessible public fields of the class"

and

Class.getDeclaredFields():
=> returns "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*."

But if I want to *include inherited fields*, that are protected but
not public, I cannot find a method for that?

Do I need to recursively analyse all the superclasses, or is there
some other method that I am missing?

TIA / grz01
 
A

Alessio Stalla

Hi,

Working, with Reflection, I find the methods

Class.getFields():
=> returns "all the accessible public fields of the class"

and

Class.getDeclaredFields():
=> returns "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*."

But if I want to *include inherited fields*, that are protected but
not public, I cannot find a method for that?

Do I need to recursively analyse all the superclasses, or is there
some other method that I am missing?

The first one you said. I have code to do it somewhere, it's not
complicated.
 
M

Mike Schilling

grz01 said:
Hi,

Working, with Reflection, I find the methods

Class.getFields():
=> returns "all the accessible public fields of the class"

and

Class.getDeclaredFields():
=> returns "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*."

But if I want to *include inherited fields*, that are protected but
not public, I cannot find a method for that?

Do I need to recursively analyse all the superclasses,
Yes.

or is there
some other method that I am missing?

No.

And if you're analyzing an abstract class to determine what methods it
declares, you'll need to check interfaces it implements (and their
superinterfaces) as well as superclasses.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top