Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Question about instanceof
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Aziz




PostPosted: 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
Sponsor
sponsor
bugzpodder




PostPosted: 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




PostPosted: 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




PostPosted: Tue Aug 01, 2006 7:12 am   Post subject: (No subject)

code:
boolean b = sword instanceof FireElement
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: