'java.util.ArrayList' 的未检查分配 [英] Unchecked assignment for 'java.util.ArrayList'

查看:35
本文介绍了'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 >'

用于:

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

如何解决?

推荐答案

您需要 new 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 而不是 ArrayList,除非您使用的是 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆