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: justin@xxxxxxxxxx (Justin Couch)
  • Subject: [Advanced-java] Basic class question
  • Date: Thu, 28 Feb 2002 07:42:19 +1100

Vladimir G Ivanovic wrote:

>   JC> Because that will always evaluate to false in this case. instanceof is a 
>   JC> runtime operator that acts on the class. If you have a variable of type 
>   JC> Class then having some random object checking for the class won't
>   JC> work.
> 
> I'm sorry, I'm confused because "obj instanceof X" will not always
> evaluate to false unless obj is *never* of type X. This is clearly not
> the case here. What were you trying to say? 

The obj he was using was of type java.lang.Class and then trying to 
compare it with instanceof. That will aways evaluate to false in the 
example code he gave. When all you have is a j.l.Class instance to check 
with, the only thing you can do is use the isInstance() method. If you 
read the docs, it says that this method is the reflection equivalent of 
the instanceof operator. Same effect, but the starting point is different.
-- 
Justin Couch                         http://www.vlc.com.au/~justin/
Java Architect & Bit Twiddler              http://www.yumetech.com/
Author, Java 3D FAQ Maintainer                  http://www.j3d.org/
-------------------------------------------------------------------
"Humanism is dead. Animals think, feel; so do machines now.
Neither man nor woman is the measure of all things. Every organism
processes data according to its domain, its environment; you, with
all your brains, would be useless in a mouse's universe..."
                                               - Greg Bear, Slant
-------------------------------------------------------------------