You can't get rid of it. The second U
is not redundant. You want the compiler to interpret the first U
as a type parameter, but it doesn't. You could also have written this:
class EventThing<T extends AbstractThing<Double>>
Note that Double
in this case is a concrete class, and not a type parameter. Compare this to the following:
class EventThing<T extends AbstractThing<U>>
Note that this has the exact same form as the first line of code above. How is the compiler supposed to know that in the first case, Double
is meant as a concrete class, while in the second case, U
is meant as a type parameter?
The compiler can't know that, and treats the U
as a concrete class, just like the Double
in the first line. The only way to let the compiler know that U
is a type parameter is to specify it as such:
class EventThing<T extends AbstractThing<U>, U>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…