I'm creating an array of ArrayLists using the following code:
ArrayList<Integer>[] list = new ArrayList[n];
As it is said that array of generics is not allowed. How is that my code compiles?
I'm creating an array of ArrayLists using the following code:
ArrayList<Integer>[] list = new ArrayList[n];
As it is said that array of generics is not allowed. How is that my code compiles?
Because you are initializing an array not the ArrayList Look at this:
ElementType [] name = new ElementType[size];
Here your element type is ArrayList
Look at this site:Array of ArrayList
refer java documentation here. You cannot create arrays of parameterized types. if it were allowed you can then create generic lists which each element of a different type. That is just not allowed. The documentation explains this well