A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Elasticsearch in Action
this week in the
Java in General
Joined: Nov 22, 2002
Aug 11, 2005 10:29:00
What is the difference between instanceOf and isInstance method.
Joined: Jan 29, 2003
Aug 11, 2005 11:23:00
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
Author and "Sun God"
Joined: May 30, 2001
Aug 11, 2005 12:58:00
Actually the name of the operator is instanceof (note the capitalization).
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>
instanceof and isInstance
using the instanceof operator
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015