Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 553
Sachin Singh Avatar asked May 07 '12 06:05

Sachin Singh


1 Answers

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.

like image 190
Adam Arold Avatar answered Sep 18 '22 18:09

Adam Arold