Computer Science Canada

Question about instanceof

Author:  Aziz [ Sun Jul 30, 2006 4:09 pm ]
Post subject:  Question about instanceof

I can dp

code:
boolean b = sword.getType() instanceof FireElement


but when I try

code:
WaterElement weakness = new WaterElement();
boolean b = sword.getType() instanceof weakness.getClass();


I get a 'illegal start of type' compiler error. Been working on this for a bit, any help would be appreciated.

Author:  bugzpodder [ Sun Jul 30, 2006 11:14 pm ]
Post subject: 

if i remember correctly, .getClass() method returns an object of Class Class. its kind of confusing, look up the API

Author:  Aziz [ Mon Jul 31, 2006 5:10 pm ]
Post subject: 

Yeah, it does, Class<E> or something-another. I figure out a different way to do what I want, however, and better IMO. Instead of comparing classes, I added an equals() method to Element and I can just compare them. However, I'd still like to figure this out, as it could have other uses. Thanks bugz

Author:  rizzix [ Tue Aug 01, 2006 7:12 am ]
Post subject: 

code:
boolean b = sword instanceof FireElement


: