【发布时间】:2014-08-22 16:05:56
【问题描述】:
编辑:我让这个例子变得更简单了
我想创建一个具有泛型参数的类,该类扩展具有泛型参数 X 的类型,并且我想引用该类型 X 而不明确声明它。
我不确定这是否也回答了这个问题Why can't I use a type argument in a type parameter with multiple bounds?
class Fruit<T> {}
// I don't want to have to redefine T e.g. <F extends Fruit<T>,T>
// because T should be implicit for Fruit (see Example of instance below)
// the below will not compile, but is roughly what I'd like
class Box<F extends Fruit<T>> {
T get( F fruit ) { return null; }
}
实例示例
class Apple extends Fruit<String>
// this is what I would like, but this won't compile with above definiton
class AppleBox extends Box<Apple> {
// String get( Apple apple ) should be implicit
}
我不想声明
class AppleBox extends Box<Apple,String>
因为字符串是这里唯一可用的选项,应该隐式知道
【问题讨论】:
标签: java