aspose file tools*
The moose likes Java in General and the fly likes Compiler warning for TreeMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Compiler warning for TreeMap" Watch "Compiler warning for TreeMap" New topic
Author

Compiler warning for TreeMap

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 388
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14432
    
  23

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 8 API documentation
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
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: 388
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Compiler warning for TreeMap