非通用类扩展通用类是什么意思
问题描述:
public class B extends C <A> {
}
这是什么意思? C需要扩展A吗?我要施加什么额外的限制,而不仅仅是说B扩展了C?
What does this mean? That C needs to extend A? What extra restriction am I putting instead of just saying B extends C?
答
在这种情况下,C
是可以采用通用参数的类,并且您将其指定为特定的类型A
作为参数.然后,B
扩展了C
的特定参数.
In this case, C
is a class that can take a generic parameter, and you are giving it a specific type A
as the parameter. Then, B
extends that specific parameterization of C
.
例如,假设:
class C<T> {
T example();
}
class B extends C<Integer> {
}
然后B.example()
将返回Integer
.