aspose file tools
The moose likes Beginning Java and the fly likes instanceof operator Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "instanceof operator" Watch "instanceof operator" New topic
Author

instanceof operator

Willie Toma
Ranch Hand

Joined: May 11, 2001
Posts: 78
There must be a reference type after the instanceof operator.
By 'reference type', you mean something like Object, and not the variable representing an Object...?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You need to name the Class or Interface that you are asking if the object is an instance of it.
if (myObj instanceof String){
//do something Stringlike
}

"JavaRanch, where the deer and the Certified play" - David O'Meara
Junilu Lacar
Bartender

Joined: Feb 26, 2001
Posts: 4118
    
    2

reference instanceof ReferenceType
ReferenceType can also be an array reference type, e.g.
ref instanceof int[] // true if ref is an int[]
ReferenceType cannot be java.lang.Class (compile time error) except when reference is declared as an Object.


------------------
Junilu Lacar
Sun Certified Programmer for the Java� 2 Platform


Junilu - [How to Ask Questions] [How to Answer Questions] [MiH]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: instanceof operator
 
Similar Threads
Test Question - Explanation?
instanceof operator
Difference between instanceof and instanceOf
Wrapping from Integer to int possible?
Instance Of operator