This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to find Object type. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to find Object type." Watch "How to find Object type." New topic
Author

How to find Object type.

Amit Wadhwaa
Ranch Hand

Joined: Feb 15, 2007
Posts: 74
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)


SCJP 5 94%<br /><a href="http://amit-wadhwa.blogspot.com/" target="_blank" rel="nofollow">My Blog</a>
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Hi Amit,

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



Perhaps this could solve your problem!



Regards,
cmbhatt


cmbhatt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to find Object type.
 
Similar Threads
Why constuctor can't be marked as final?
does inheritance break the encapsulation or data hiding?
Parent class n derived class
Have you even wanted to do this in Java: ${x.a.b.c}
Please explain