Solved

"Inspection" of other classes

Posted on 2004-04-21
4
271 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
  • 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

762 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now