为什么Wild Cards不能用于通用类和放大器方法声明? [英] Why Wild Cards can't be used in generic class & method declaration?
本文介绍了为什么Wild Cards不能用于通用类和放大器方法声明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class A< X extends Number&列表> {bb} {b
是这样的,您可以将它用作类中的类型。那里的通配符甚至意味着什么?如果你不能在任何地方使用它,为什么要有一个类型参数?
$ p
$ b是允许的。这样的声明是不允许的。
class A< ;?扩展Number&列表> {}
有没有关于Java为何限制我们这样做的逻辑解释? b
$ b&
< T extends Number>的实际区别是什么?
& < ;?扩展数字> ;?
解决方案$ c> T
Declaration like this :
class A<X extends Number & List> { }
is allowed.Whereas declaration like this is not allowed.
class A<? extends Number & List> { }
Is there any logical explanation about why Java restricts us to do that?
& what's the actual difference between
<T extends Number> & <? extends Number>?
解决方案The whole point of a type parameter like
T
is so that you can use it as a type inside the class. What would a wildcard there even mean? If you can't use it anywhere, why have a type parameter at all?这篇关于为什么Wild Cards不能用于通用类和放大器方法声明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文