We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › find if class is descendant from...
Page Index Toggle Pages: 1
find if class is descendant from...? (Read 486 times)
find if class is descendant from...?
Mar 29th, 2008, 12:26pm
 
Is there an easy way to find a class descends from another class? I traverse through a list with objects that all implement the same interface. I want to filter out the few that descent from a particular abstract class. I did find the 'getSuperclass' method but that only returns the direct superclass, while the abstract one I want to check is sometimes super, and sometimes the super of the super. I've now just put a cast in a try..catch, it works but I just don't like the look of it.
Re: find if class is descendant from...?
Reply #1 - Mar 29th, 2008, 3:16pm
 
if (object instanceOf abstractClass){
//do something
}

try this, replacing object and abstractClass with your stuff of course =)
Re: find if class is descendant from...?
Reply #2 - Mar 30th, 2008, 12:13pm
 
ah thanks... Smiley
instanceof should be lower case though
Page Index Toggle Pages: 1