Java泛型:特殊用法< T扩展了对象&界面> [英] Java Generics: Special usage <T extends Object & Interface>
本文介绍了Java泛型:特殊用法< T扩展了对象&界面>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我经常发现这样的代码在Java中使用泛型:
I often find code which uses generics in Java like this:
public static <T extends Object & Interface> foo(T object) {
...
}
因为在Java中,每个类都从对象类继承,所以我不确定extends Object
是否具有特殊含义或是否用于特殊目的.有人可以告诉我使用此背景是否有其他背景,或者当您使用<T extends Interface>
时这是隐式给出的吗?
Since in Java every class inherites from object class I'm not sure if extends Object
gives a special meaning or is used for special purposes. Can anyone tell me if there is a different background using this or this is implicit given when you take <T extends Interface>
?
推荐答案
<T extends Object & Interface>
Object
显然是多余的,通常等于
That Object
is clearly redundant and typically equals to
<T extends Interface>
请注意,强烈建议不要使用Interface
作为类名.
Note that using Interface
as a class name is highly discouraged.
这篇关于Java泛型:特殊用法< T扩展了对象&界面>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文