Java Generics Syntax for arrays

前端 未结 6 1630
梦谈多话
梦谈多话 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 12:51

    Mr Josh Bloch says:

    "Prefer lists to array because arrays are covariant and generics are invariant'

    You could perhaps do:

    List> someListArray;
    

    This may give some performance hit (not even noticable i bet) but you will get better type safety at compile time.

    but I think the question should be more around "why" you need this?

提交回复
热议问题