R
Roger Levy
I have a simple problem using generics. Suppose I want to make a
parameterized holder class, call it Singleton, that contains a single
object o, and instances of Singleton containing objects of comparable
type should themselves be comparable by these objects. So I want
something like
public class Singleton<T1 extends Comparable<? super T1>> implements
Comparable<Singleton<T2>> {
T1 x;
public int compareTo(Singleton<T2> s) {
return x.compareTo(s.x);
}
}
while constraint that T1 and T2 are themselves mutually comparable.
At any rate, the above is not legal Java 1.5 code.
Any suggestions will be much appreciated!
Many thanks,
Roger Levy
parameterized holder class, call it Singleton, that contains a single
object o, and instances of Singleton containing objects of comparable
type should themselves be comparable by these objects. So I want
something like
public class Singleton<T1 extends Comparable<? super T1>> implements
Comparable<Singleton<T2>> {
T1 x;
public int compareTo(Singleton<T2> s) {
return x.compareTo(s.x);
}
}
while constraint that T1 and T2 are themselves mutually comparable.
At any rate, the above is not legal Java 1.5 code.
Any suggestions will be much appreciated!
Many thanks,
Roger Levy