| Author |
Compiler warning for TreeMap
|
M Burke
Ranch Hand
Joined: Jun 25, 2004
Posts: 375
|
|
When I do the put() I get a warning in Java 1.5: TreeMap vo = new TreeMap(); Object[] rc = (Object[]) irc.next(); Integer locOrder = (Integer) rc[0]; MenuItem mI = (MenuItem) rc[1]; vo.put(locOrder, mI); "Type safety: The method put(Object, Object) belongs to the raw type TreeMap. References to generic type TreeMap<K,V> should be parameterized" How do I resolve this?
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
You should use generics to indicate the type of keys and values, a new feature of Java 1.5. TreeMap<Integer, MenuItem> vo = new TreeMap<Integer, MenuItem>();
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Joanne Neal
Rancher
Joined: Aug 05, 2005
Posts: 3011
|
|
|
Change the declaration toRead up on Generics (a new Java 1.5 feature) to understand this.
|
Joanne
|
 |
M Burke
Ranch Hand
Joined: Jun 25, 2004
Posts: 375
|
|
Thanks, that works. Is there a doc out there that talks about 1.5 changes?
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Originally posted by M Burke: ... Is there a doc out there that talks about 1.5 changes?
J2SE 5.0 in a Nutshell [ October 06, 2005: Message edited by: marc weber ]
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Layne Lund
Ranch Hand
Joined: Dec 06, 2001
Posts: 3061
|
|
Originally posted by M Burke: Thanks, that works.  Is there a doc out there that talks about 1.5 changes?
Sun's official list
|
Java API Documentation
The Java Tutorial
|
 |
 |
|
|
subject: Compiler warning for TreeMap
|
|
|