List 是一个原始类型.对泛型类型 List<E> 的引用应该参数化 [英] List is a raw type. References to generic type List&lt;E&gt; should be parameterized

查看:24
本文介绍了List 是一个原始类型.对泛型类型 List<E> 的引用应该参数化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的语法

List synchronizedpubliesdList = Collections.synchronizedList(publiesdList);

我收到以下语法错误:

List 是原始类型.对泛型类型 List 的引用应该被参数化.

请提出解决方案.

推荐答案

我相信

List 是原始类型.对泛型类型 List 的引用应该被参数化

List is a raw type. References to generic type List should be parameterized

不是错误,而是警告.

如果您打算使用 Java,理解泛型是基石,所以我建议您应该查看 Java 的教程页面:

Understanding generics is a cornerstone if you are planning to use Java so I suggest that you should check out Java's tutorial pages about this:

java泛型教程

因此,如果您知道 publiesdList 中包含什么类型的对象,那么您可以这样做:

So if you know what type of objects are contained in publiesdList, than you can do this:

List<YourType> synchronizedpubliesdList = Collections.synchronizedList(publiesdList);

如果列表中有多种类型的对象,则可以使用通配符:

If there are multiple types of objects in your list than you can use a wildcard:

List<?> synchronizedpubliesdList = Collections.synchronizedList(publiesdList);

或者如果你只是想摆脱警告,你可以像这样抑制它:

Or if you just want to get rid of the warning than you can suppress it like this:

@SuppressWarnings("rawtypes")
List synchronizedpubliesdList = Collections.synchronizedList(publiesdList);

不过不推荐后者.

这篇关于List 是一个原始类型.对泛型类型 List<E> 的引用应该参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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