How to solve this Java type safety warning? (Struts2)

Posted by Nicolas Raoul on Stack Overflow See other posts from Stack Overflow or by Nicolas Raoul
Published on 2010-05-28T07:42:46Z Indexed on 2010/05/28 7:51 UTC
Read the original article Hit count: 214

Filed under:
|
|
|
Map session = ActionContext.getContext().getSession();
session.put("user", user);

This code generates a warning: Type safety: The method put(Object, Object) belongs to the raw type Map. References to generic type Map should be parameterized.

Map<String, Serializable> session = (Map<String, Serializable>)ActionContext.getContext().getSession();
session.put("user", user);

This code generates a warning: Type safety: Unchecked cast from Map to Map.

The getSession method belongs to Struts2 so I can't modify it. I would like to avoid using @SuppressWarnings because other warnings can be useful.

I guess all Struts2 users in the world faced the same problem... is there an elegant solution?

© Stack Overflow or respective owner

Related posts about java

Related posts about generics