• Post Reply Bookmark Topic Watch Topic
  • New Topic

how can i deal with this unchecked warning?  RSS feed

 
Sylven Yip
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi~
i store a HashMap object in the session attribute.
now i get it:
HashMap<String,Object> hm=session.getAttribute("map");

find: java.util.Map
need: java.util.Map<java.lang.String,java.lang.Object>
 
Akshay Kiran
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
do a downcast

This will give you an unchecked warning and there's no way to avoid it if you're going to mix generic and non-generic code.
if you're so sure that you're getting back a . In any case, the code you wrote will give a compile time error and not an unchecked warning.
[ October 06, 2007: Message edited by: Akshay Kiran ]
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add an annotation: @SuppressWarnings("unchecked") to the method in which you are doing this.

[ October 07, 2007: Message edited by: Jesper Young ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!