java 在java中?,E,T之间有什么区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5526955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In java what's the difference between ?, E, T
提问by czetsuya
Possible Duplicate:
Java Generics
可能重复:
Java 泛型
Hi,
你好,
Can anyone please explain the difference of the three and each proper usage?
谁能解释一下这三者的区别以及各自的正确用法?
Thanks, been googling but I'm still confused on how to use each.
谢谢,一直在谷歌搜索,但我仍然对如何使用每个人感到困惑。
czetsuya
切苏亚
采纳答案by jbrookover
I'm assuming you're talking about Generics. The 'E' and 'T' are placeholders and can be used interchangeably in class definitions. By convention 'E' is an Element and 'T' is a Type. The question mark is a placeholder for an unknown type. You often see things like this:
我假设你在谈论泛型。'E' 和 'T' 是占位符,可以在类定义中互换使用。按照惯例,'E' 是一个元素,'T' 是一个类型。问号是未知类型的占位符。你经常会看到这样的事情:
List<? extends MyObject> x;
This implies that 'x' is a list of objects that are subclasses of MyObject, but we don't know what they are exactly.
这意味着 'x' 是一个对象列表,它们是 MyObject 的子类,但我们不知道它们到底是什么。
See: http://docs.oracle.com/javase/tutorial/java/generics/genTypes.html
请参阅:http: //docs.oracle.com/javase/tutorial/java/generics/genTypes.html
回答by Amir Afghani
E, T, K, V, or any other generic type variables are just placeholders - they don't have any intrinsic association. You can even use lowercase letters for generic type variables, but conventionally you use a single capital letter. Read the generics tutorialfrom Sun.
E、T、K、V 或任何其他泛型类型变量只是占位符 - 它们没有任何内在关联。您甚至可以对泛型类型变量使用小写字母,但通常使用单个大写字母。阅读Sun的泛型教程。