Unchecked assignment for 'java.util.ArrayList'

前端 未结 1 1173
星月不相逢
星月不相逢 2021-02-20 01:24

I get the warning:

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

for:



        
1条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 02:19

    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 myLocations = new ArrayList<>();
    

    Or just be explicit:

    private ArrayList myLocations = new ArrayList();
    

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

    0 讨论(0)
提交回复
热议问题