Question about instanceof
Author |
Message |
Aziz

|
Posted: 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. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
bugzpodder

|
Posted: Sun Jul 30, 2006 11:14 pm Post subject: (No subject) |
|
|
if i remember correctly, .getClass() method returns an object of Class Class. its kind of confusing, look up the API |
|
|
|
|
 |
Aziz

|
Posted: Mon Jul 31, 2006 5:10 pm Post subject: (No 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 |
|
|
|
|
 |
rizzix
|
Posted: Tue Aug 01, 2006 7:12 am Post subject: (No subject) |
|
|
code: | boolean b = sword instanceof FireElement |
|
|
|
|
|
 |
|
|