aspose file tools
The moose likes Java in General and the fly likes How to get implementation class name from an interface object ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to get implementation class name from an interface object ?" Watch "How to get implementation class name from an interface object ?" New topic
Author

How to get implementation class name from an interface object ?

shahabas shabeer
Ranch Hand

Joined: Feb 23, 2004
Posts: 49
Hi friends,

I am trying to debug an existing application. I have handle to a java object (say a.b.MyClass xyz). 'MyClass' is an interface. I want to know the name of the class which has implemented this interface. In other words, I want to know the actual type of a java object xyz. xyz.getClass().getName() returns the interface name and not the actual implementation class name. Is there a way to get the actual implementation class name ?

Thanks in advance!!


The greatest pleasure in life is doing what peoples say you can not do.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35257
    
    7
Yes, that's possible. You'd call ".getClass().getName()" on the object - that will return a String with the fully-qualified class name.


Android appsImageJ pluginsJava web charts
Bill Cruise
Ranch Hand

Joined: Jun 01, 2007
Posts: 148
Ulf is right. Can you show us how you're declaring your reference and how you're getting an instance of your object. I tried this:



and got the following output:

Object type: testcode.MyClass
shahabas shabeer
Ranch Hand

Joined: Feb 23, 2004
Posts: 49
Thank you Dittmer. Thank you Cruise..

Yes..That works. I got the Class name and I fixed the bug.

Cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to get implementation class name from an interface object ?
 
Similar Threads
constructor question
Interfaces and Objects
implementing same interface by more than one beans (glashfish v2 + netbeans 6.7)
how to get Clients CPU information on Server using Java RMI
RMI using Proxy classes