This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes isInstance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "isInstance" Watch "isInstance" New topic
Author

isInstance

Arathi Raj
Ranch Hand

Joined: Nov 22, 2002
Posts: 90
HI,
What is the difference between instanceOf and isInstance method.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
You can say

someObject.getClass().isInstance( x )

when you don't know what class someObject is at compile time. You must know what class you're comparing at compile time when you say

x instanceOf SomeHardCodedClass


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joshua Bloch
Author and "Sun God"
Ranch Hand

Joined: May 30, 2001
Posts: 124
Actually the name of the operator is instanceof (note the capitalization).

Regards,

Josh


Joshua Bloch <br />Author of <a href="http://www.amazon.com/exec/obidos/ASIN/0201310058/ref=ase_electricporkchop" target="_blank" rel="nofollow">Effective Java</a> and coauthor of <a href="http://www.amazon.com/exec/obidos/ASIN/032133678X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Java Puzzlers</a>
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: isInstance
 
Similar Threads
instanceof problem
Exception Handling(Checked/Unchecked)
isinstance
using the instanceof operator
instanceof and isInstance