Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to instantiate

LinkedList<?> op = new LinkedList<?>();

But I get error

Cannot instantiate the type LinkedList<?>

Why is it that this cannot be instantiated in Java?

share|improve this question
What do you want to achieve? If you want a linked list that accepts any kind of object, new LinkedList<Object>() is the correct thing to do. – Heinzi Apr 6 '13 at 12:17
up vote 4 down vote accepted

If you don't know what object type will be inside the list, why are you using generics? <?> means I don't know (<? extends Object>).

It's been a long time since I programmed in Java but my understanding is that wildcard generics are made to match something, e.g. when you are declaring a method parameter, you can use a wildcard so that different generics can be passed to it. Also, a variable can use a wildcard to accept different generic types.

However, when creating an instance, you have to supply a specific type. The wildcard just doesn't have any sense there.

That's why

List<?> list = new LinkedList();
List<?> list = new LinkedList<Object>();
List<?> list = new LinkedList<MyObject>();

Are all possible but

List<?> list = new LinkedList<?>();


share|improve this answer
Fun fact: starting with Java 7, you can write List<?> list = new LinkedList<>(); letting the compiler infer the type from the context, which is the target type List<?>. Whether it infers List<?> or List<Object> makes no difference to the outcome which is in no way more useful than writing List<?> list = new LinkedList<?>();. In the end, the actual answer is “because the specification says so”. – Holger Mar 16 at 12:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.