未经检查的'java.util.ArrayList'赋值 [英] Unchecked assignment for 'java.util.ArrayList'
问题描述
我收到警告:
未经检查的'java.util.ArrayList'赋值给'java.util.ArrayList< com.test.mytest>'
Unchecked assignment for 'java.util.ArrayList' to 'java.util.ArrayList < com.test.mytest >'
for:
private ArrayList<LocoList> myLocations = new ArrayList();
如何解决?
推荐答案
你想要新的ArrayList<>();
以便你使用正确的泛型类型。目前,您在 =
的右侧使用原始类型。所以你想要:
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<>();
或者只是明确:
private ArrayList<LocoList> myLocations = new ArrayList<LocoList>();
(您还可以考虑将变量的类型设置为 List< LocoList>
而不是 ArrayList< LocoList>
,除非您使用 ArrayList
- 特定成员。我个人也会放弃我的前缀。)
(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.)
这篇关于未经检查的'java.util.ArrayList'赋值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!