未经检查的'java.util.ArrayList'赋值

gog*_*loi 11 java android warnings arraylist

我收到警告:

未经检查的'java.util.ArrayList'赋值给'java.util.ArrayList <com.test.mytest>'

对于:

private ArrayList<LocoList> myLocations = new ArrayList();
Run Code Online (Sandbox Code Playgroud)

怎么解决?

Jon*_*eet 22

您希望new ArrayList<>();使用正确的泛型类型.目前你正在使用右侧的原始类型=.所以你要:

private ArrayList<LocoList> myLocations = new ArrayList<>();
Run Code Online (Sandbox Code Playgroud)

或者只是明确:

private ArrayList<LocoList> myLocations = new ArrayList<LocoList>();
Run Code Online (Sandbox Code Playgroud)

(您可能还会考虑使用变量的类型List<LocoList>而不是ArrayList<LocoList>,除非您使用的是ArrayList特定成员.我个人也会放弃"我的"前缀.)