Niclas Hedhman schrieb:
> Anyone knows why this doesn't work??
>
>    ArrayList<String>[] array = new ArrayList<String>[0];

Simply put: That's because arrays are covariant. Let's extend your 
example:

  Object[] objArray = array;

This one's OK, ArrayList<String> is a subtype of Object, therefore, 
ArrayList<String>[] is a subtype of Object[].

  ArrayList<Integer> intList = new ArrayList<Integer>();
  intList.add(42);
  objArray[0] = intList;

Still OK ...

  String s = array[0].get(0);

=> ClassCastException.

For this reason, it's not possible to use generic arrays in Java.

cu,
   Raffi

-- 
The difference between theory and practice is that in theory, there is
no difference, but in practice, there is.

[EMAIL PROTECTED] · Jabber: [EMAIL PROTECTED]
PGP Key 0x5FFDB5DB5D1FF5F4 · http://keyserver.pgp.com

_______________________________________________
general mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/general

Reply via email to