这个接口定义中的尖括号是什么意思? [英] What do the angle brackets mean in this Interface definition?
问题描述
我对Java编程相对比较陌生,并且遇到了一个接口声明和一个实现它的类:
public interface Abcd< E extends Comparable< E>> {
......
......
......
}
public class AbcdImpl< E extends Comparable< E>>实施Abcd< E> {
......
......
......
}
你能解释< E>
signify?
E
代表一个类型,这个字母不一定是E,它可以是任何东西,但通常人们会使用像 T
,ķ
,电子
, V
。使用某种方式表示该类型用于何种类型的信件是有道理的。例如,在 Map
接口 Map< K,V>
中,K代表键,V代表值。 / p>
至于< E扩展Comparable< E>>
,这意味着类型E是通用类型 AbcdImpl
需要自己实现 Comparable
接口(为它自己)。所以任何一个类 E
必须有一个方法
compareTo(E obj )
用于比较 E
的一个实例与另一个 E
。
的实例
I am relatively new to Java Programming and I came across this declaration of an interface and a class that implements it:
public interface Abcd<E extends Comparable<E>>{
......
......
......
}
public class AbcdImpl<E extends Comparable<E>> implements Abcd<E>{
......
......
......
}
Can you explain what <E extends Comparable<E>>
stands for and typically what does <E>
signify?
E
stand for a type, the letter doesn't need to be E it can be anything, but usually people will use letters like T
,K
,E
,V
. It makes sense to use a letter that somehow signifies what the type is used for. For instance in the Map
interface Map<K,V>
, K is for key and V is for value.
As for <E extends Comparable<E>>
it means that the type E that is the generic type of AbcdImpl
needs to itself implement the Comparable
interface (for itself). So any class E
has to have a method
compareTo(E obj)
for comparing one instance of E
to another instance of E
.
这篇关于这个接口定义中的尖括号是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!