File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing classes

 
Dev Cunningham
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 260
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use the isAssignableFrom(Class cls) of the Class object to check the same.
hope u gottit
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Dev Cunningham
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic