• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LinkedList

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>();
 
Ranch Hand
Posts: 531
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic