I'd like to know what the first <T>
represents in the following line of Java code. I've read several tutorials on generics but none of the examples have 2 generics before the method name. Thanks.
public <T> Provider<T> scope(Key<T> key, Provider<T> unscoped);
The first <T>
is the actual type parameter declaration, i.e. it says that the method is generic and has a type parameter T
.
The second <T>
is simply part of the method's return type, i.e. the method returns a Provider<T>
.
If the first <T>
were omitted, the return type Provider<T>
would be invalid, since T
would not be a recognised identifier/name for a type. T
is only recognised as a type because the first <T>
introduces it as such.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With