
-----------------------------------
Aziz
Sun Jul 30, 2006 4:09 pm

Question about instanceof
-----------------------------------
I can dp

boolean b = sword.getType() instanceof FireElement

but when I try

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.

-----------------------------------
bugzpodder
Sun Jul 30, 2006 11:14 pm


-----------------------------------
if i remember correctly, .getClass() method returns an object of Class Class.    its kind of confusing, look up the API

-----------------------------------
Aziz
Mon Jul 31, 2006 5:10 pm


-----------------------------------
Yeah, it does, Class 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

-----------------------------------
rizzix
Tue Aug 01, 2006 7:12 am


-----------------------------------
boolean b = sword instanceof FireElement
