Java Generics Syntax for arrays

前端 未结 6 1619
梦谈多话
梦谈多话 2020-12-10 12:17

What data structure does the following declaration specify?

 List[] myArray;

I think it should declare an array where each

6条回答
  •  遥遥无期
    2020-12-10 13:05

    List[] someListArray;
    

    gives you an:

    array of ( List of ArrayList )
    

    But due to limitations in Java generics (bug 6229728) you can only actually create:

    array of List
    

    and cast it:

    List[] someListArray = (List[]) new List[5];
    

提交回复
热议问题