Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What does this error description mean?

4 views
Skip to first unread message

Ravi

unread,
Feb 28, 2010, 10:03:31 AM2/28/10
to
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 li2 = new LinkedList(li);

But still if you please answer the question.

Eric Sosman

unread,
Feb 28, 2010, 10:46:01 AM2/28/10
to
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
eso...@ieee-dot-org.invalid

rossum

unread,
Feb 28, 2010, 11:15:21 AM2/28/10
to
On Sun, 28 Feb 2010 07:03:31 -0800 (PST), Ravi <ra.ra...@gmail.com>
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);

The Java Compiler was expecting to see a LinkedList<Integer> on the
right as well as on the left.

Saying "raw type" means "the base type without the generic < ... >
bit". Saying "unchecked" means that the compiler cannot tell whether
li contains Integers or something else. If it contains something else
then you may get a runtime error.

You do not show us the line where li is declared. It should look
something like:

LinkedList<Integer> li = new LinkedList<Integer>();

rossum

Roedy Green

unread,
Feb 28, 2010, 4:30:22 PM2/28/10
to
On Sun, 28 Feb 2010 07:03:31 -0800 (PST), Ravi <ra.ra...@gmail.com>
wrote, quoted or indirectly quoted someone who said :

>
> warning: [unchecked] unchecked call to
>LinkedList(java.util.Collection) as a member of the raw type
>java.util.LinkedList

see http://mindprod.com/jgloss/generics.html

You need a lot of background to understand what you have to do to fix
it.
--
Roedy Green Canadian Mind Products
http://mindprod.com

The major difference between a thing that might go wrong and a thing that cannot possibly go wrong is that when a thing that cannot possibly go wrong goes wrong it usually turns out to be impossible to get at or repair.
~ Douglas Adams (born: 1952-03-11 died: 2001-05-11 at age: 49)

Lew

unread,
Feb 28, 2010, 5:53:59 PM2/28/10
to
Ravi wrote, quoted or indirectly quoted someone who said :

>
>> warning: [unchecked] unchecked call to
>> LinkedList(java.util.Collection) as a member of the raw type
>> java.util.LinkedList

Roedy Green wrote:
> see http://mindprod.com/jgloss/generics.html
>
> You need a lot of background to understand what you have to do to fix
> it.

Not so much background is needed for this particular error. All you have to
do is add the '<Integer>' to the 'List' instantiation to make sure both sides
match.

That much background is obtained simply by reading the link Eric provided
<http://java.sun.com/docs/books/tutorial/java/generics/index.html>
or the mindprod.com link referenced above, or the free PDF from Joshua Bloch's
/Effective Java/ on generics available from the java.sun.com site
<http://java.sun.com/docs/books/effective/generics.pdf>
or any of the IBM Developerworks or other resources found from
<http://www.google.com/search?q=Java+generics+introduction>

People act like generics is so hard to get. It's more like checkers - there
aren't that many rules to get a basic understanding, although mastery does
require deep study. Sort of like the Java language itself.

OTOH, computer programming generally requires a lot of background to
understand what you have to do. Too many people plunge into the discipline
with a scattershot approach, throwing things into source code in blind hope
that they'll get what they want. Programming requires study, thought and
understanding for one to be effective. Trying to learn solely by asking the
newsgroup is no substitute; one absolutely must develop the habit and skill of
looking things up and figuring them out.

--
Lew

Roedy Green

unread,
Mar 2, 2010, 4:06:14 PM3/2/10
to
On Sun, 28 Feb 2010 17:53:59 -0500, Lew <no...@lewscanon.com> wrote,

quoted or indirectly quoted someone who said :

>


>People act like generics is so hard to get. It's more like checkers - there
>aren't that many rules to get a basic understanding, although mastery does
>require deep study. Sort of like the Java language itself.

An analogy is even a 10 year old can do differential calculus, just by
applying the rote rules, but to understand just what you are doing and
why takes quite a bit more work.

This reminds me of a story. When I was about three years old I found
a drawing my Dad and made with wiggly lines and little boxes and
copied it. I put his drawing somewhere else and left mine in its
place.

Dad found the drawing and for while was under the illusion I had
designed a telephone circuit.

0 new messages