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 isInstance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "isInstance" Watch "isInstance" New topic


Arathi Raj
Ranch Hand

Joined: Nov 22, 2002
Posts: 90
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).



Joshua Bloch <br />Author of <a href="" target="_blank" rel="nofollow">Effective Java</a> and coauthor of <a href="" target="_blank" rel="nofollow">Java Puzzlers</a>
I agree. Here's the link:
subject: isInstance
It's not a secret anymore!