File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "LinkedList" Watch "LinkedList" New topic
Author

LinkedList

Lethe Knight
Greenhorn

Joined: Sep 07, 2005
Posts: 1
Hi,

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!

Lethe
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Hi,

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
 
Similar Threads
Generics Question
Which collection class would you use to store the objects?
Interview
Generics refresher
depth of a binary tree ?