Initialize ArrayList

后端 未结 4 1559
我寻月下人不归
我寻月下人不归 2021-01-05 03:25

Why I can initialize ArrayList, like this:

ArrayList x = new ArrayList(Arrays.asList(1,2));

But got Error whe

4条回答
  •  孤城傲影
    2021-01-05 04:17

    Because Arrays.asList(1,2) will implicitly return a List.

    You can fix this by using the following idiom:

    ArrayList x = new ArrayList(Arrays.asList(1l,2l));
    

提交回复
热议问题