Reputation: 5723
I come up with a code that uses a syntax like this:
public <A extends B> double[][] foo(C arg) {
.... }
I get a couple of questions by viewing it.
a) The return type of 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?
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 public <A> double[][] foo(C arg)
?
c) Finally I suppose that <> have to do with Java generics but even then I have seen declaration like 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.
Upvotes: 1
Views: 88
Reputation: 48434
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.Upvotes: 2