Java question about ArrayList[] x

后端 未结 6 1563
臣服心动
臣服心动 2021-02-06 08:41

I have always had this one issue with arrays of ArrayLists. Maybe you can help.

//declare in class
private ArrayList[] x;

//in constructor
x=new          


        
6条回答
  •  忘了有多久
    2021-02-06 09:10

    Well, it seems you want to avoid the warning about Generics when you simply write

    ArrayList[] x=new ArrayList[n];

    as well as remove the compilation error, of x=new ArrayList[n];

    You can use the generic type to satisfy both the conditions, something like:

    ArrayList x[]=new ArrayList[n];
    

    You might want to refer to the link below for knowing more about generics: https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

提交回复
热议问题