• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Types

 
Bob Sherry
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please consider the following Java program:

import java.util.*;
public class BackLister {
public static<T> List<T> backward(List<? extends T>input)
{
List<T> output = new LinkedList<T>();
for(T t : input )
output.add(0, t);
return output;
}
}

I do not understand the use of the question mark in declaring the
method backward. I am hoping that somebody can explain it to me.

Thanks

Bob
 
Campbell Ritchie
Sheriff
Posts: 48371
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It means you can use an unspecified type there, which might be the same a T, or a subclass of T (or if T is an interface, something implementing T).

Go through the Java Tutorials (look for "wildcards") for lots more detail.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic