Question: What's the explanation for the following:

```
public class GenericsTest {
    //statement 1
    public ArrayList<Integer>[] lists;

    public GenericsTest()
    {
            //statement 2
        lists = new ArrayList<Integer>[4];
    }
}

```

The compiler accepts statement 1. Statement 2 is flagged by the compiler for "generic array creation". 

A good explanation I've seen regarding disallowing generic arrays is [this one](http://www.ibm.com/developerworks/java/library/j-jtp01255.html), arguing that since arrays are covariant and generics are not you could subvert the generic typing if you allowed generic arrays. 

Leaving aside the argument over whether the language should go to the extreme lengths of creating this kind of complicated inconsistency in the treatment of generics to keep you from shooting yourself no matter how hard you try (and if anyone knows of any good discussions on the relative merits/demerits of the issue please post, I'd be interested to see the arguments), why should statement (1) be allowed if (2) isn't?

Answer: 
It's because you can't create, but you can **use** them:

```
public class GenericsTest {
    //statement 1
    public ArrayList<Integer>[] lists;

    public GenericsTest()
    {
        //statement 2
        lists = new ArrayList[4];
        //statement 3
        lists[0].add(new Integer(0));
        //statement 4
        lists[0].add(new String(""));
    }
}

```

Statement 3 is possible, statement 4 will lead to a compiler error.
So the actual question is: Why is there no error for declaring a generic array? ?

You will always get an error at the point you do something erroneous. Adding an error where there isn't technically a problem just adds to a clutter (although an editor might want to point that out to you).

In some circumstances you may want to bend the rules a bit with an unchecked cast. There's no need to force the code to be littered with more warning suppressions than necessary (other than to point out the folly).