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, ie 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, ie 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.