Java 泛型

简介

Object & <?> & <T>

<T> T

reference

public static <T> List<T> backwards (List<? super T> input) {  
       List<T> output = new ArrayList<T>();  
       return output;  
}
<T>
I'm declaring an arbitrary type T for this method,
which can be anything (non-primitive) for each call of the method.
List<T>
This method will return a List containing elements of that type T.
List<? super T> input
This method will take a parameter called input, 
which is a List containing elements of type T, or any super-type of T. For example, 
if T is Integer, input could be a List<Integer>, List<Number>, or List<Object>."
public static <T> List<T> ->> public static List<T>
public static List<T> doesn't declare a type parameter,
and so must already be in the scope of a generic type parameter T on the declaring class


评论

暂无评论