A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Joined: Sep 07, 2005
Sep 07, 2005 20:05:00
I am having a problem with using
When I try to use the addFirst method. Eclipse says that "references to type
<E> should be parameterized."
Can someone give me an example of how to use
I have something along the lines of
list = new
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!
author and iconoclast
Joined: Jul 08, 2003
Sep 07, 2005 20:52:00
Welcome to JavaRanch!
It should be a warning, not an error, right?
In any case, you want to learn about
, a new feature in JDK 1.5.
The generic-ized version of the line you're seeing the warning on would look like
<GeoSegment> list = new
[Jess in Action]
Joined: Sep 19, 2004
Sep 07, 2005 21:23:00
This no longer valid
although it will be permitted indefinitely:
list = new
What is this a list of? You have not specified and the compiler feels uncomfortable adding objects to a list whose content is unspecified.
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
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:
depth of a binary tree ?
Which collection class would you use to store the objects?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015