| Author |
SE1.4 VS 1.6
|
Robert Richardson
Greenhorn
Joined: Feb 10, 2007
Posts: 12
|
|
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
Sheriff
Joined: Sep 28, 2004
Posts: 16681
|
|
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
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Robert Richardson
Greenhorn
Joined: Feb 10, 2007
Posts: 12
|
|
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
Joined: Jan 28, 2003
Posts: 3026
|
|
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:
|
Steve
|
 |
Robert Richardson
Greenhorn
Joined: Feb 10, 2007
Posts: 12
|
|
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
Joined: Jul 15, 2009
Posts: 536
|
|
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.
|
[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api
|
 |
 |
|
|
subject: SE1.4 VS 1.6
|
|
|