class that can find class's data member

class that can find class's data member

Post by DC » Fri, 24 Jan 2003 14:25:04



Is that any built-in class in java api that can list the class member
(especially data value) of a class?

For instance, if class MyClass has instance variable x and y, then when an
instance of MyClass is created and sent to this special class, then this
special class will able to find out what is the instance variable (including
the data type, variable name, public/static etc.) in this object/class.

Regards,

 
 
 

class that can find class's data member

Post by Jon Skee » Fri, 24 Jan 2003 23:22:55



> Is that any built-in class in java api that can list the class member
> (especially data value) of a class?

> For instance, if class MyClass has instance variable x and y, then when an
> instance of MyClass is created and sent to this special class, then this
> special class will able to find out what is the instance variable (including
> the data type, variable name, public/static etc.) in this object/class.

I think you're looking for the java.lang.reflect package - however I
would warn that in *most* cases, reflection is unnecessary, and it's
worth designing more carefully to avoid using it. However, when it *is*
necessary, it's great.

--

http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too