这里的第一篇文章参数...Java的:不能返回泛型集合延伸的返回类型
这是我定义泛型类:
public class TimeSeries<T extends Number> extends TreeMap<Integer, T>{
...
public Collection<Number> data() {
return this.values();
}
}
上下文的位。 TimeSeries基本上是一种特定种类的TreeMap,其中键是整数,值是数字。
我的问题是数据的方法有以下错误打破:
error: incompatible types: Collection<T> cannot be converted to Collection<Number>
return this.values();
^
where T is a type-variable: T extends Number declared in class TimeSeries
值方法只返回T的集合到底为什么我不能回到这一点的方法,如果我有特别声明那T扩展数字?
在此先感谢。
'this.values()'的类型是什么? –
退货类型为:收藏 –