File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Implementing Comparable With a Generic Type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Implementing Comparable With a Generic Type" Watch "Implementing Comparable With a Generic Type" New topic
Author

Implementing Comparable With a Generic Type

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

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

Joined: Jan 10, 2007
Posts: 247
The person class should be written so:

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Implementing Comparable With a Generic Type