Two Laptop Bag*
The moose likes Beginning Java and the fly likes Comparable interface java 1.5 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 » Java » Beginning Java
Bookmark "Comparable interface java 1.5" Watch "Comparable interface java 1.5" New topic
Author

Comparable interface java 1.5

Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
Hi all,

Could someone please post an example of how
to use the comparable interface with java 1.5?

Thank you.
-Cathy.
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762




Since you bind the interface to the Employee type, the compareTo method signature takes an argument of type Employee.

-Jeff-


Books: Agile Java, Modern C++ Programming with TDD, Essential Java Style, Agile in a Flash. Contributor, Clean Code.
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I haven't dabbled with Java 5.0 yet, so I have a question related to this thread: can you implement Comparable "bound" to different types? I imagine something like:

Does this work? (I should probably download Java 5.0 and try it myself. However, I don't want to mess up my development environment at home while I'm in the middle of a big project. I'll definitely look into it next semester, though.)

Layne


Java API Documentation
The Java Tutorial
Cathy Song
Ranch Hand

Joined: Aug 24, 2003
Posts: 270
Thanks Layne and Jeff

-Cathy.
Jeff Langr
author
Ranch Hand

Joined: May 14, 2003
Posts: 762
You're welcome!

Layne --

The compiler appears to prevent it.

-Jeff-
 
jQuery in Action, 2nd edition
 
subject: Comparable interface java 1.5
 
Similar Threads
comparable Interface
Couple of Problems
Interface
sorting of a list having bean object
difference between Comparator and Comparable interface