• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SE1.4 VS 1.6

 
Robert Richardson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:

The following compiles and runs using jdk1.6



But when I modify it to complile using jdk1.4 as below



I get two errors Name (or firstnameSort) is not abstract (OK I buy that) and does not override abstract method compare (or compareTo) (looks to me like they do)...

Any tips would be appreciated.

Thanks
Robert Richardson
 
Henry Wong
author
Marshal
Pie
Posts: 21016
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The types of the parameters to compareTo() and compare() are due to generics. Without generics, they are defined (in Java 1.4) as taking Object type parameters.

Henry
 
Robert Richardson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry:
Thanks for your reply. I didn't do a good job asking the question. I can rewrite the code and eliminate the errors I mentioned by changing the reference variable type from Name to Object.


I want to cast the Object to Name so I can use its methods but the complier still thinks n1 and n2 are Objects not Names.
I'm sure I'm missing something fundamental but it escapes me.
Thanks for yor help.
Robert
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your casting incorrectly. The dot operator has precedence over the cast, so you have to modify the order to ensure you cast first, then call the method on the casted reference. Do it using parenthesis:
 
Robert Richardson
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My worst fears have been realized. My problem was trivial. Oh well! Nothing to do but press on.
Thanks to you guys for your help.
Robert
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I get two errors Name (or firstnameSort) is not abstract (OK I buy that) and does not override abstract method compare (or compareTo) (looks to me like they do)...


This error is basically given when the compiler finds that you are not fulfilling the contract of the interface(concrete classes should implement all methods of the interface). May be a quick look at the java1.4 api docs would have solved the problem there and then.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic