Alex Rivera | Logout

What is static <T> List<T> methodName (List<? super T> input)

Asked 2012-07-03T02:26:24.653
16

I have the following code but i am confused with all the generics.

public static <T> List<T> backwards (List<? super T> input) {  
       List<T> output = new ArrayList<T>();  
       return output;  
}

My understanding is that I have a public method named backwards which creates an arraylist implementing the List interface and returning the arraylist. My question is what actually I am saying to the compiler with the following part......

static <T> List<T> backwards (List<? super T> input)
Edit
Report

1 Answer

47

You are saying to the compiler:

<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>."

answered 2012-07-03T03:48:22.650

Your Answer