列表是一种原始类型。对泛型类型的引用< E>应该参数化 [英] List is a raw type. References to generic type List<E> should be parameterized

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

问题描述

以下是我的语法

 列出synchronizedpubliesdList = Collections.synchronizedList(publiesdList); 

我收到以下语法错误:

List是一个原始类型。对泛型类型的引用< E>应该参数化。



请提出解决方案。 / div>

我相信


List是一种原始类型。引用泛型类型List应该被参数化

不是错误,而是一个警告。



如果您打算使用Java,那么了解泛型是一个基石,所以我建议您应该查看java的教程页面以了解这个:

java泛型教程



因此,如果您知道 publiesdList 中包含的对象类型,则您可以执行此操作:

 列表与LT; YourType> synchronizedpubliesdList = Collections.synchronizedList(publiesdList); 

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

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

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

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

但不推荐后者。


Below is my syntax

List synchronizedpubliesdList = Collections.synchronizedList(publiesdList);

I am getting a syntax error of:

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

Please suggest the solution.

解决方案

I believe that

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

is not an error, but a warning.

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 generics tutorials

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);

the latter is not recommended however.

这篇关于列表是一种原始类型。对泛型类型的引用&lt; E&gt;应该参数化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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