wood burning stoves
The moose likes Beginning Java and the fly likes LinkedList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "LinkedList" Watch "LinkedList" New topic


Lethe Knight

Joined: Sep 07, 2005
Posts: 1

I am having a problem with using LinkedList.

When I try to use the addFirst method. Eclipse says that "references to type LinkedList<E> should be parameterized."

Can someone give me an example of how to use LinkedList appropriately.

I have something along the lines of

LinkedList list = new LinkedList();
list.addFirst(gs); //where gs is an instance of GeoSegment, a class I wrote

which is causing the parameterized error mentioned above.

Thanks for the help!

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199


Welcome to JavaRanch!

It should be a warning, not an error, right?

In any case, you want to learn about generics, a new feature in JDK 1.5.

The generic-ized version of the line you're seeing the warning on would look like

LinkedList<GeoSegment> list = new LinkedList<GeoSegment>();

[Jess in Action][AskingGoodQuestions]
Rick O'Shay
Ranch Hand

Joined: Sep 19, 2004
Posts: 531
This no longer valid Java although it will be permitted indefinitely:

>> LinkedList list = new LinkedList();

What is this a list of? You have not specified and the compiler feels uncomfortable adding objects to a list whose content is unspecified.

>> list.addFirst(gs);

Try to get in the habit of specifying what's in your collections. Also, use the least specific type you can get away with. Here I am using a List:

List<Apple> list = new LinkedList<Apple>();

list.add( new Apple() ); // Calling add( Apple ) with an Apple, no problem.

list.add( new Hummer() ); // Whoa buster! There is no add( Hummer ) method!
[ September 07, 2005: Message edited by: Rick O'Shay ]
I agree. Here's the link: http://aspose.com/file-tools
subject: LinkedList
It's not a secret anymore!