'is subclass' check out.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Rami_Abramson
Posted On:   Wednesday, May 22, 2002 01:40 AM

			
Hello,

How is it possible during runtime to know whether an instance of class X is one of the subclasses of Y ?

thank you,

Rami

Re: 'is subclass' check out.

Posted By:   Simon_Ablett  
Posted On:   Wednesday, May 22, 2002 05:17 AM

Try 'myClass.class.getSuperClass()'. This will retrieve a handle to to the superclass that your class (i.e. 'myClass' in the example) extends.

or,

alternate solution 1: use 'myClass instanceof yourClass' which will check whether or not 'myClass' is an instance of the type of class represented by 'yourClass'. Where 'yourClass' could be one of 'myClass' supertypes

or,

alternate solution 2: use 'myClass.class.isInstance(yourClass)' which behaves in a similiar way to 'instanceOf'

Regards.
About | Sitemap | Contact