Alex Rivera | Logout

What does List<?> mean in java generics?

Asked 2009-12-04T04:02:38.433
65

What does List<?> mean, does it mean simply a list of objects of unspecified type?

Googling for the string <?> returns nothing useful (:

Edit
Report

1 Answer

3

List is an interface you can implement yourself and also implemented by some of the Java collections, like Vector.

You can provide compile-time typing information using the angled brackets. The most generic type would be Object, which would be List<Object>. The <?> you see is indicating a List of some subclass of Object or an Object. This is like saying List<? extends Object>, or List<? extends Foo>, where the List contains objects of some subclass of Foo or objects of Foo itself.

You can't instantiate a List; it's an interface, not an implementation.

answered 2009-12-04T04:13:09.247

Your Answer