Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to find Object type.

 
Amit Wadhwaa
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic Qs: How to find the actual concrete class of an object?

Problem: I have this thousands of line of code and there's this object and I want to debug one of its methods. The problem is the whole code uses factory pattern and it's becoming very hard for me to find the actual class of the object.

The code is something like
a.callMethodWhichIWantToDebug();


Few lines before that we have something like a=getA();
getA(){
B b=getC().createB();
a=getC().getA(b)
return a;
}
getC()
{
D d=getE().getD();
...
and soon

Ofcourse D, E,B are all interfaces.


Is there a easier way to find the implementation class of the object

I cannot use a debugger as I have to deploy the program on a server (it doesnt take long though)to run it.
And hence setting up a debugger would take up some time(stubs/skeletons for code)
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call getClass() on any object, which returns java.lang.Class. Then use, e.g., Class.getName() to get the name of the class.
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,

I have a little idea; you can play with it:



Perhaps this could solve your problem!



Regards,
cmbhatt
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic