Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
780 views
in Technique[技术] by (71.8m points)

java - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...