I was reading up on generics in Java here and here, and while I understand the point of having them, I'm having a little trouble understanding the header of a generic Java method. I'm used to:
public returnType methodName(parameters){body}
What keeps confusing me is the specification of a generic method declaration:
public *genericType* returnType methodName(parameters){body}
or
public static <T> void fromArrayToCollection(Collection<T> c) {}
What is this type declaration (<T> between static and void) affecting? Is it just outlining the type that the method parameters can be?
T"Collection<T>in the signature implicitly have that same meaning?T. For example, you could writevoid foo(Collection<String> strs) { String bar = ""; }(which compiles), but you could also write<String> void foo(Collection<String> strs) { String bar = ""; }which does not, sinceStringis a type variable, notjava.util.String. Similarly, if it were inferrable thatTmight mean a type variable, there is no way of knowing whether you mean that or some class which you forgot to import,T.