Solved

"Inspection" of other classes

Posted on 2004-04-21
4
276 Views
Last Modified: 2011-04-14
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
0
Comment
Question by:JNic
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
ACrasborn earned 100 total points
ID: 10877769
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
 
LVL 37

Assisted Solution

by:zzynx
zzynx earned 25 total points
ID: 10878225
"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
 
LVL 1

Author Comment

by:JNic
ID: 10878287
Ahhhhhhhhhhhh :-D

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

Kindest regards,

Nic
0
 
LVL 37

Expert Comment

by:zzynx
ID: 10878374
Thanks for accepting
:)
That keeps us answering your future questions too
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question