ArrayList<int> list1 = new ArrayList<int>(); // Error
ArrayList<int[]> list2 = new ArrayList<int[]>(); // Works fine
Generics do not work for primitive types but work fine with Array of primitives. Why?
Follow up:
The only reason I can think of it is because the Array is an object so generics work with them. But if that is so then why couldn't a primitive int array be autoboxed to corresponding Integer wrapper class automatically?
Integer arr = new int[5]; // Error
Integer[] arr = new int[5]; // Error
Integer a = 5; // Works fine (autoboxing)
If someone could shed some light on this would be highly appreciated or if I am missing something of how it's represented internally. Thanks.