This class is intended to represent a pair of objects of arbitrary types – what a python dev might think of as a 2-tuple.
public class Pair<DD extends Comparable<DD>,VV> implements Comparable< Pair<DD,VV> > {
DD d;
VV v;
// Implementation removed.
}
I want to make a new subclass called NumberPair – the only difference is that while Pair can conceivably contain any two classes of object, my NumberPair class will only be allowed to contain numbers.
Can anybody tell me how to express this?
PS. Admittedly this looks like a silly design given that anywhere we might use this class we could also use a Map – please ignore that for now.
I’m not sure if I completely get the problem, but I think this might be what you’re looking for:
This forces both type parameters to extend Number.