Links

Lists

Latest Updates

Ruby On Rails List
Python list
Advanced Java
The JavaScript List
Apache Users
Full Disclosure
Linux Security

Search the archives!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Advanced-java] Basic class question


  • From: vladimir@xxxxxxx (Vladimir G Ivanovic)
  • Subject: [Advanced-java] Basic class question
  • Date: Wed, 27 Feb 2002 14:15:15 -0800

"JC" == Justin Couch <justin@xxxxxxxxxx> writes:

  JC> The obj he was using was of type java.lang.Class and then trying to 
  JC> compare it with instanceof. 

Actually, I don't think this is the case. "xClass" was the class object
in his message, not not "obj". "obj" was some random object, an object
he wanted to test for class membership.

So Sybille Breunig's proposed 

   > if (obj instanceof X)
   >     // do anything

should work just fine.

--- Vladimir

--------
Vladimir G. Ivanovic                        http://leonora.org/~vladimir
2770 Cowper St.                                         vladimir@xxxxxxx
Palo Alto, CA 94306-2447                                 +1 650 678 8014


That will aways evaluate to false in the 
  JC> example code he gave. When all you have is a j.l.Class instance to check 
  JC> with, the only thing you can do is use the isInstance() method. If you 
  JC> read the docs, it says that this method is the reflection equivalent of 
  JC> the instanceof operator. Same effect, but the starting point is different.