This week's book giveaway is in the Agile forum.
We're giving away four copies of The Software Craftsman and have Sandro Mancuso 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 The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to find Object type." Watch "How to find Object type." New topic

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

Few lines before that we have something like a=getA();
B b=getC().createB();
return a;
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="" target="_blank" rel="nofollow">My Blog</a>
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

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!


I agree. Here's the link:
subject: How to find Object type.