Re: What does this error description mean?
On 2/28/2010 10:03 AM, Ravi wrote:
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?
It means that the compiler isn't sure the right-hand
side is a LinkedList<Integer> rather than a mere LinkedList.
You're saying "Java, the thing on the left should contain
nothing but Integers, but I'm not telling you what the thing
on the right holds." Java replies "As far as I know, the thing
on the right contains a mixture of Integers, Strings, and
JToggleButtons, so I can't be sure this will work right."
Edit:
It should have been infact: LinkedList li2 = new LinkedList(li);
You may be taking a step backward here (although since I
don't know what li and li2 are supposed to contain, I can't
be sure). Your fix amounts to saying "Java, the thing on the
left can contain anything at all, without restriction," and Java
says "In that case, it doesn't matter what the thing on the right
contains." This is all well and good, but it's not exactly
"progress." If you do in fact know that your Collections hold
only Integers, it would be better to find a way to let Java know,
too.
But still if you please answer the question.
The Tutorial has a section on generics that you might find
helpful:
http://java.sun.com/docs/books/tutorial/java/generics/index.html
--
Eric Sosman
esosman@ieee-dot-org.invalid