generic LinkedList and warnings - newbie question

R

R

Hello everybody.

I'm using Eclipse (Linux) and JDK 1.5 with generics.
Eclipse points a warning in my generic code.

This is my code:

// generic LinkedList - this is OK
LinkedList <Record> Results = new LinkedList <Record> ();

but later on when I call add method with Record object as a parameter:

Results.add(rec);

Eclipse shows a warning:
The method add(Object) belongs to raw type LinkedList.
References to generic type LinkedList<E> should be parametarized.

Yes I know it's only a warning but I don't know why it occured.
I saw few examples on the web and all were almost the same as mine.

thanks in advance for your help
best regards
R
 
J

John C. Bollinger

R said:
I'm using Eclipse (Linux) and JDK 1.5 with generics.
Eclipse points a warning in my generic code.

This is my code:

// generic LinkedList - this is OK
LinkedList <Record> Results = new LinkedList <Record> ();

but later on when I call add method with Record object as a parameter:

Results.add(rec);

Eclipse shows a warning:
The method add(Object) belongs to raw type LinkedList.
References to generic type LinkedList<E> should be parametarized.

Yes I know it's only a warning but I don't know why it occured.
I saw few examples on the web and all were almost the same as mine.

It occurred because the type of the rec _variable_ is not Record or a
subclass of Record. It doesn't matter if you're certain that rec will
always contain a reference to a Record -- if you don't declare it that
way then static type checking cannot verify it.
 
T

Tony Morris

R said:
Hello everybody.

I'm using Eclipse (Linux) and JDK 1.5 with generics.
Eclipse points a warning in my generic code.

This is my code:

// generic LinkedList - this is OK
LinkedList <Record> Results = new LinkedList <Record> ();

but later on when I call add method with Record object as a parameter:

Results.add(rec);

Eclipse shows a warning:
The method add(Object) belongs to raw type LinkedList.
References to generic type LinkedList<E> should be parametarized.

Yes I know it's only a warning but I don't know why it occured.
I saw few examples on the web and all were almost the same as mine.

thanks in advance for your help
best regards
R

This should help.
http://qa.jtiger.org/GetQAndA.action?qids=70&showAnswers=true

--
Tony Morris
Software Engineer, IBM Australia.
BInfTech, SCJP 1.4, SCJP 5.0, SCJD

http://www.jtiger.org/ JTiger Unit Test Framework for Java
http://qa.jtiger.org/ Java Q&A (FAQ, Trivia)
http://xdweb.net/~dibblego/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top