方法返回类型包含子类定义 [英] Method return type contains subclass definition
问题描述
public< A extends B> double [] [] foo(C arg){
....}
I I come up with a code that uses a syntax like this: I get a couple of questions by viewing it. a) The return type of b) Why there is a subclass declaration inside a return type? Since A is a subclass of B where do we override or add any methods/members etc? To me it seems that it's a subclass containing just the same methods/members of the base class A. Isn't so? So is there any difference in writing c) Finally I suppose that <> have to do with Java generics but even then I have seen declaration like
这篇关于方法返回类型包含子类定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
$ b a) foo(C arg)
的返回类型是< A扩展B>双[] []
?这是什么意思?例如,我会理解返回类型,比如 double [] []
>,但我无法确定前一个修饰符(可能?)< A b)为什么在返回类型中有一个子类声明?由于A是B的一个子类,我们在哪里重写或添加任何方法/成员等?对我来说,它似乎是一个只包含基类A的相同方法/成员的子类。不是吗?那么在编写
public< A> c)最后,我认为<>必须处理Java泛型,但是甚至那么我已经看到类似于
D
的声明,其中T用于参数化原始类型 D
。在这里,我尝试删除<>(因为我不明白它们代表的是什么),但是编译器抱怨了。
double [] []
。 < A扩展B>
部分是通用方法
扩展B
意味着只有泛型类型 A
扩展或者实际上在这个方法中实现 B
是允许的。
public <A extends B> double[][] foo(C arg) {
.... }
foo(C arg)
is <A extends B> double[][]
? What does this mean? I would understood a return type like double[][]
for example, but I cannot determine what does the previous modifier (maybe?) <A extends B>
does?public <A> double[][] foo(C arg)
?D<T>
which T is used to parametrize the raw type D
. Here I tried to remove the <> (since I don't understand what they stand for) but compiler complains.
double[][]
. The <A extends B>
part is the parametrization of the generic methodextends B
implies that only generic types A
extending or actually implementing B
are allowed in this method.