While compiling a program in Java I got this big WARNING
warning: [unchecked] unchecked call to
LinkedList(java.util.Collection) as a member of the raw
type java.util.LinkedList
on this line:
LinkedList<Integer> li2 = new LinkedList(li);
What does this warning mean?
Edit:
It should have been infact: LinkedList<Integer> li2 = new LinkedList<Integer>(li);
But still if you please answer the question.
Raw types are unchecked. Use
You should never use raw types in new code. It’s only provided for backward compatibility reason. See JLS 4.8
The emphasis was theirs, not mine.
You added a correction to the original question implying that you want to work with raw types specifically. This seems to defeat the purpose of the type safety provided by generics, but you can always use
List<Object>to accomplish this. It’s no longer raw, so it’s guaranteed to work in the future, although it really doesn’t give you any type safety.Depending on the context, you may also do
List<?>for unbounded wildcards.