aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instanceof Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "instanceof" Watch "instanceof" New topic
Author

instanceof

amrit singh
Ranch Hand

Joined: Nov 03, 2000
Posts: 42
what this mean
"you cannot use a java.lang.Class object reference
or a String representing the name of the class as right operand
of instanceof operator"
Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
you can not say if(String instanceof String)
Sivaram Ghorakavi
Ranch Hand

Joined: Nov 30, 2000
Posts: 56
instanceof operator should only be used against the Reference of Object. If you really want to find what class time it try using isInstance(Object obj) method from class Class.
Vlad G
Greenhorn

Joined: Dec 28, 2000
Posts: 17
I guess what it really says is that you cannot do something as follows:
<pre>
String s = new String("some string");
Class clazz = s.getClass();
if (s instanceof clazz) {} // incorrect!
if (s instanceof "String.class") {} //incorrect!
</pre>
regards,
VG.

[This message has been edited by Vlad G (edited January 02, 2001).]
 
 
subject: instanceof
 
Similar Threads
Does this exist?
instanceOf
java
Difference between instanceof and instanceOf
Checking for object type