I am trying to understand this method signature:
public final <T> FluentIterable<T> transform(Function<? super E,T> function)
I understand that transform returns a FluentIterable<T>
, but I don't understand what the <T>
before FluentIterable<T>
means?
Further, in Function<? super E,T>
, I understand what ? super E
means, but I can't imagine how the compiler can check this - isn't E unknown at compile time, so how shall the compiler know, if ?
is a supertype of E
?
<T>
means that this is a method with the generic type parameter T
. This is similiar to <T>
after a class name (like List<T>
), just for methods.
E
is not unknown at compile time. E
is also a generic type parameter defined in the class definition:
public abstract class FluentIterable<E> extends Object implements Iterable<E>
When you create an instance of this class the compiler knows the type of E
.