First of all, I think those who have customized Java standards can have Java create generic arrays, but they weigh it out and think it's a good thing to do, just say my guess:
If we write the following code is no problem:
List<string> a = new arraylist<string> ();
Well, that's why the array doesn't work:
list<string>[] arr = new arraylist<string> [10];
Let's take a look at the difference between an array variable and a normal variable: the array variable arr and the normal variable A are all in the stack, but! Arr[0] in the heap. So? So we have the following example:
list<string>[] arr = new arraylist<string> [10];object[] Orr = arr; list<stringbuffer> buf = new arraylist<stringbuffer> (); orr[0] = buf; list<string> str = arr[0]; String val = Str.getvalue ();
It can be found that the No. 0 element in the heap is list<stringbuffer>, but Arr[0] still points to it, if it is a normal variable, it is not possible, so even if the introduction of generics, is not safe; the last sentence, because the compiler adds a string conversion , resulting in classcastexception, generics are meant to be safe, if the security of the array is not guaranteed, why are there superfluous?
This paper mainly refer to: http://www.blogjava.net/deepnighttwo/articles/298426.html
Why does Java not let you create a generic array