This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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: 44515
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!