• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implementing Comparable With a Generic Type

 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to learn how to use the Comparable interface for Java 5.0+. In the Java 5.0 API, when I implement the Comparable interface in the code below, I get a warning that says that Comparable is "unchecked".

Will somebody explain to me why Comparable has a generic type and how to implement the Comparable interface in Java 5.0 and up.

 
victor kamat
Ranch Hand
Posts: 247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The person class should be written so:

 
Kaydell Leavitt
Ranch Hand
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Victor. I appreciate the help.

I think that my next task would be to implement the following methods:

toString()
equals()
hashCode()

And, now I've got that done.
[ December 27, 2008: Message edited by: Kaydell Leavitt ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic