java - Reference to Generic type Lis<E> should be parameterized

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:36   1732   0

As the java has evolved from the old java without generic to java with advanced generic containers. You will see the following code will be flagged as an error by the Java compiler.

List children = config_.getElements(name);

you will probably see the following error when you run some recent version of compilers. Here is the error message.

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

There are serveral ways that you can get pass it. first and the simplest way is to use the Generic types List<T>, here is the code

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

But this is based on the assumption that you know the type in advance, but you may not know the type in advance, you will need to do the following.

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

And you can even suppress the warnings by the folowing.

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

So my case, I simple do the folllowing.

 List<?> children = config_.getElements(name);

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP