我希望在我的API中提供类似于这样的东西:
class Foobar extends AbstractThing<Double>
class EventThing<Foobar> {
public Foobar getSource();
public Double getValue();
}
所以我写了这个:
class EventThing<T extends AbstractThing<U>> {
public T getSource();
public U getValue();
}
但是Java无法解决U
问题。
使用EventThing<T extends AbstractThing<U>,U>
可以解决,但第二个U
实际上是多余的,因为AbstractThing已经定义了类型。所以我希望摆脱它。
U
是实际类型还是泛型类型参数。Java 要求每个泛型类型参数都要明确声明,这是有充分理由的。无论你觉得怎样,这并不是编译器的“缺失特性”。 - ColinD