File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 24199

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: 1710
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.
It's not a secret anymore!