• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get implementation class name from an interface object ?  RSS feed

 
shahabas shabeer
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that's possible. You'd call ".getClass().getName()" on the object - that will return a String with the fully-qualified class name.
 
Bill Cruise
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Dittmer. Thank you Cruise..

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

Cheers
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!