• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

instanceof

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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"
 
Ranch Hand
Posts: 177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can not say if(String instanceof String)
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
reply
    Bookmark Topic Watch Topic
  • New Topic