File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedList

 
Lethe Knight
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>();
 
Rick O'Shay
Ranch Hand
Posts: 531
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic