"Inspection" of other classes

Hi,

Is there a way to get the names of methods and attributes of other classes  (also if they are declared private)?

Lets fx. say that I would like to list all the attribute names(and values), and method names from the Color class.

What would I do??

Kind regards,

Nic
LVL 1
JNicAsked:
Who is Participating?
 
ACrasbornConnect With a Mentor Commented:
Try this:

        Class c = Color.class;
        Method[] m = c.getDeclaredMethods();
        Field[] f = c.getDeclaredFields();

You can find more information in package "java.lang.reflect"

A.C.
0
 
zzynxConnect With a Mentor Software engineerCommented:
"Reflection" is the word.
You can even invoke the methods you found this way.
Read all about it at http://java.sun.com/docs/books/tutorial/reflect/
0
 
JNicAuthor Commented:
Ahhhhhhhhhhhh :-D

Thank you both! I LOVE THIS PLACE!!!!

Kindest regards,

Nic
0
 
zzynxSoftware engineerCommented:
Thanks for accepting
:)
That keeps us answering your future questions too
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.