× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hello All,
I'm wondering if anybody has experience implementing Comparable<T> over a
generic class. I know I could make sure the generic type implements
Comparable, but is that the only way?

Basically, I'm just creating a generic Pair class and would like to
implement Comparable, or Comparator, so that the Pair could be successfully
used in a TreeMap or any other sortable collection.

I could do this:
public class Pair<T1 extends Comparable, T2 extends Comparable> implements
Comparable<T1, T2>...

But would prefer this:
public class Pair<T1, T2> implements Comparable<T1, T2>...

If the full source would be helpful, just let me know.

Also, is there a way to make a truly immutable generic class? Something like
adding a mutable object like Date would be immutable in the Pair object.
Normally I would just return a new Date(), but is there way to make it
immutable in another object?

Thanks in advance,
--
James R. Perkins

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.