Studyon Minte9.com
Fundamentals (Docs)

Study

Wildcards



In generics, an unknown type is represented by the wildcard character "?".
To specify a cage capable of holding some kind of animal:

	Box<? extends Number> box = ...;

Read "? extends Number" as "an unknown type that is a subtype of Number, possibly Number itself".

	public class BoxDemo3 {
	    
	    public static void main(String[] args) {
		
		Box<Number> boxN = new Box<>();
		Box<? extends Number> boxI = new Box<>(); // look here
		Box<? extends Double> boxD = new Box<>();
		
		BoxDemo3 bx = new BoxDemo3();
		bx.boxTest(boxN); // OK
		bx.boxTest(boxI); // OK
		bx.boxTest(boxD); // OK
	    }
	    
	    public void boxTest(Box<? extends Number> box) { // look here
		// ...
	    }
	}

You can also specify an unknown type with an unbounded wildcard, which simply looks like <?>. 
An unbounded wildcard is essentially the same as saying <? extends Object>.


http://docs.oracle.com/javase/tutorial/java/generics/wildcards.html