Two Laptop Bag*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes compareTo() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "compareTo() method" Watch "compareTo() method" New topic
Author

compareTo() method

Jomy George
Ranch Hand

Joined: Jan 13, 2011
Posts: 65
hi friends,

in book i have read that, compareTo() method can take object of its class as argument and it is unsafe to define this method with Object reference. but when i tried with object of same class it get error.


when compile i get error saying

Name.java:2: Name is not abstract and does not override abstract method compareT
o(java.lang.Object) in java.lang.Comparable
class Name implements Comparable
^
1 error


whats wrong with this code?
thanks in advance....

Jim Jonides
Ranch Hand

Joined: Oct 12, 2010
Posts: 42
I think you need to use the generic format by giving the parameter of <Name> to the interface of Comparable:



Devil is in the detail.
Jomy George
Ranch Hand

Joined: Jan 13, 2011
Posts: 65
thanks jim
now works fine
 
Consider Paul's rocket mass heater.
 
subject: compareTo() method
 
Similar Threads
comparable Interface
Error in K&B Study Guide?
SE1.4 VS 1.6
implementing compareTo() - doubt
generics