aspose file tools*
The moose likes Java in General and the fly likes Comparing classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparing classes" Watch "Comparing classes" New topic
Author

Comparing classes

Dev Cunningham
Greenhorn

Joined: Oct 12, 2001
Posts: 9
How do I test if one class is an 'instance of' another class when both of the operands are, in fact, classes?
I can check whether an object is an instance of a class, but in this case I have two classes -- dynamic at run time -- and I want to see if one implements the other.
Thanks!
william kane
Ranch Hand

Joined: Nov 21, 2000
Posts: 260
use the isAssignableFrom(Class cls) of the Class object to check the same.
hope u gottit


Help me!Help you!!!
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Notice that assignableFrom has the *reverse logic* of instanceof! That is:
(a instanceof B) <==> (B.class.assignableFrom(a.getClass()))
[ May 20, 2002: Message edited by: Ilja Preuss ]

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dev Cunningham
Greenhorn

Joined: Oct 12, 2001
Posts: 9
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing classes