I have a class Range, the declaration of which reads:
public abstract class Range<T extends Comparable<T>>
I’d like to create a class RangeSet that takes one generic type — a Range. In the body of the RangeSet class, however, I’d like to be able to refer to two generic types
- The Range the RangeSet was typed with, and
- The
T extends Comparable<T>the Range was typed with
Is this possible?
No, you would have to make your
RangeSethave two type parameters. For example:However, are you sure that you really need the type
Rof theRange? Couldn’t you just make the methods inRangeSetaccept aRange<T>instead ofR?