How to solve this Java type safety warning? (Struts2)
- by Nicolas Raoul
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?