File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Question about Types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Question about Types" Watch "Question about Types" New topic

Question about Types

Bob Sherry

Joined: Jun 27, 2008
Posts: 20
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.


Campbell Ritchie

Joined: Oct 13, 2005
Posts: 45255
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.
I agree. Here's the link:
subject: Question about Types
It's not a secret anymore!