Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Advanced-java] BAsic class question
- From: sbr@xxxxxxxxxxx (Sybille Breunig)
- Subject: [Advanced-java] BAsic class question
- Date: Wed, 27 Feb 2002 09:42:56 +0100
Why don't you use :
if (obj instanceof X)
// do anything
----- Original Message -----
From: "Justin Couch" <justin@xxxxxxxxxx>
To: <advanced-java@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, February 27, 2002 9:34 AM
Subject: Re: [Advanced-java] BAsic class question
> dovle wrote:
>
> > Suppose I have a class X and I obtain the
> > Class xClass = X.class ;
> >
> > Later, I want to check if an object is instance(exactly) of this class.
> >
> > what is the best way to do this ?
> >
> > obj.getClass() == xClass ;
> >
> > It works always ? ( aka : there is only one Class object instantiated
for a
> > class).
>
> Nope. Best bet is to look at the reflection stuff. You'll want the
> isInstance() method in Class.
>
>
> --
> 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
> -------------------------------------------------------------------
>
> _______________________________________________
> Advanced-java mailing list
> Advanced-java@xxxxxxxxxxxxxxxxxxxxxx
> http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
>
- Follow-Ups:
- [Advanced-java] BAsic class question
- From: Justin Couch
- [Advanced-java] BAsic class question
- References:
- [Advanced-java] BAsic class question
- From: dovle
- [Advanced-java] BAsic class question
- From: Justin Couch
- [Advanced-java] BAsic class question
- Prev by Date: [Advanced-java] BAsic class question
- Next by Date: [Advanced-java] BAsic class question
- Previous by thread: [Advanced-java] BAsic class question
- Next by thread: [Advanced-java] BAsic class question
- Index(es):