Question: It may be asked somewhere but I could not find it.

Please tell me the exact difference between:

```
ArrayList list = new ArrayList();

```

and

```
ArrayList<?> list = new ArrayList();

```

I cannot figure out what is the exact difference between these two.

Thanks...

Answer: 
`ArrayList<?>` simply means "any type." In other words, any type of `ArrayList` can be assigned to such variable. That could be `ArrayList<Integers>`, `ArrayList<JButton>` or anything else. Using the wildcard alone, without the keyword super (followed by a type), means that you cannot **ADD** anything to the list defined as `ArrayList<?>`. `ArrayList` alone however, means the old style type-less `ArrayList` which you can do all sorts of operations including `add`.

```
List<?> list;
List<Integer> ints = new ArrayList<Integer>();
List<Integer> strings = new ArrayList<Integer>();
list = ints; // valid
list = strings; // valid
list.add("new"); // compile error

```

**UPDATE:**

Suppose I have following method:

```
void insert(List list) {
   // loop through list, do whatever you like
   list.add("my string"); // dangerous operation 
}

```

Now if I call `insert(ints)` compiler will generate a warning but will not prevent me of adding a String to a list of integers. Changing method to following:

```
void insert(List<?> list) {
   // loop through list, do whatever you like
   list.add("my string"); // compiler error on this dangerous operation
}

```

would prevent me of doing such an operation.
There is no difference in the behaviour.

The real difference is in the way that the compiler treats them. In the first case, you are telling the compiler "treat this as a *raw* type" and don't try to do any generic static typing. In the second case, you are saying "treat this as a generic type" ... but that the actual type parameter is "some type that we want to avoid specifying here".

And note that the `<?>` wildcard syntax cannot be used where a definite type is required.

@SJuan76 commented:

> 
> "(I guess they didn't add the feature just to get some code to produce compilation errors)"
> 
> 
> 

Well, actually you could say that that *is* that they did. Or more precisely, they left the old form so that old (pre-Java 5) code would continue to compile *without* compilation errors using a Java 5+ compiler.