• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get implementation class name from an interface object ?

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic