18

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.

Adam Arold
  • 29,285
  • 22
  • 112
  • 207
Sachin Singh
  • 739
  • 4
  • 12
  • 29
  • 6
    This is a warning, not an error. This line of code will compile but javac will not do all the type checks. – Jerome May 07 '12 at 06:39

4 Answers4

40

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.

Adam Arold
  • 29,285
  • 22
  • 112
  • 207
  • Perfect. I got past this same issue by Adding Generic<> to the declaration and Generic() to the instantiation in my code. thanks. – Ken Ingram Dec 07 '14 at 22:42
8

You need to give it the correct generic type e.g.

List<String> publiesdList = ...
List<String> synchronizedpubliesdList = Collections.synchronizedList(publiesdList);
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
1

You may define "publiesdList" this way:

List<String> publiesdList = new List<String>();

The warning will dissappear.

Oleg Hmelnits
  • 114
  • 1
  • 10
0

I've had the same warnings in Eclipse and just click on the warning sign and get the option of adding a type argument to the Hash, List, Array or what have you. Big list of discussion here What is a raw type and why shouldn't we use it?

Community
  • 1
  • 1
Douglas G. Allen
  • 2,203
  • 21
  • 20