首页 > Java 泛型为什么不能写 <? is extended by V>? 如何表达相同的意思?

Java 泛型为什么不能写 <? is extended by V>? 如何表达相同的意思?

比如我有 class Aclass B extends Aclass template<A>class template<B>
要在 template<B> 里存一个名叫 template_parent 的实例变量指向一个 template<A>,而 template<A>template_parentnull。定义 template_parent 时想写 template<? is extended by B> 但是不让写。为什么 Java 不让这么写?我该怎么可以绕开这个限制来表达相同的意思?

Update: 好吧我欢乐多~~ <? is extended by B><B> 是一样的。。。


不是一样的哦。如果你想指定B的parent,或者B的parent的parent……可以用<? super B>


<? is extended by V>可以用<? super V>来表示。

【热门文章】
【热门文章】