• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

compareTo() method

 
Jomy George
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to use the generic format by giving the parameter of <Name> to the interface of Comparable:

 
Jomy George
Ranch Hand
Posts: 68
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks jim
now works fine
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic