Performance of "instanceof"

Ulf Zibis Ulf.Zibis at gmx.de
Tue Jan 13 04:49:11 PST 2009


Hi,

I'm just interested, how "instanceof" works behind the scenes. Does it 
simply string-compare the names of the classes, and in fail, do the same 
with the super class in  loop, or is there some sophisticated algorithm.

I'm asking, because I want to know, which is faster:
-   obj instanceof mypackage.MyClass
-   obj.getClass() == mypackage.MyClass.class
-   obj.name().equals(objOfMyClass.name()) (assuming, each MyClass has 
it's own name, as it is the fact for Charset subclasses.)

- Ulf





More information about the hotspot-dev mailing list