Unchecked assignment for 'java.util.ArrayList'

依然范特西╮ 提交于 2020-01-01 08:43:24

问题


I get the warning:

Unchecked assignment for 'java.util.ArrayList' to 'java.util.ArrayList < com.test.mytest >'

for:

private ArrayList<LocoList> myLocations = new ArrayList();

How to fix it?


回答1:


You want new ArrayList<>(); so that you use the right generic type. At the moment you're using the raw type on the right hand side of =. So you want:

private ArrayList<LocoList> myLocations = new ArrayList<>();

Or just be explicit:

private ArrayList<LocoList> myLocations = new ArrayList<LocoList>();

(You might also consider making the type of the variable List<LocoList> instead of ArrayList<LocoList>, unless you're using ArrayList-specific members. I'd also ditch the "my" prefix, personally.)



来源:https://stackoverflow.com/questions/44078128/unchecked-assignment-for-java-util-arraylist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!