File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Getting component type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Getting component type" Watch "Getting component type" New topic

Getting component type

Barry Brashear
Ranch Hand

Joined: Jun 05, 2001
Posts: 303
If an object of type componet is coming into a method, what is the best
way to detemine it's type, such as checking if it's a JInternalFrame, or

Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
You mean, if you have an reference, of compile-time type Component, how do you find out the run-time type of the object to which it points?

Usually, you would use the "instanceof" operator.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Lionel Badiou
Ranch Hand

Joined: Jan 06, 2005
Posts: 140
Hello Barry,

You may try .

Hope that helps,

Lionel Badiou
CodeFutures Software
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You can also use reflection:

Of course, this may be of only limited use depending what you need to do with this information once you have it.


Java API Documentation
The Java Tutorial
I agree. Here's the link:
subject: Getting component type
It's not a secret anymore!