Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find the name of an object

Status
Not open for further replies.

rajarajan

Programmer
Jul 16, 2001
33
IN
Hi,
I've got a Java object with me.
I'm able to find the name of the class of which it is an instance, the attributes of that object etc., using the reflect package.
But how is it that I find the actual name of that object.

Regards,
Rajan
 
Calling getClass() on the object will return a Class object. From that Class object you can call getName() which returns a String object representing the name of the Class.
eg.

Code:
YourObject obj=new YourObject();
String objectType=obj.getClass().getName();
Note that this sets objectType to the fully qualified name of the entity. eg. If your object was of type Object objectType would be set to "Ljava.lang.Object"

hope that helped MYenigmaSELF:-9
myenigmaself@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top