If you always assume that it is a HashMap<String, String> , why not just do it?
HashMap<String, String> hMap; public void setHashMap(HashMap<String, String> map){ hMap = map; }
If you need something more general that any Map will accept:
public void setHashMap(Map<String, String> map){ if (map != null) hMap = new HashMap<String, String>(map); else hMap = new HashMap<String, String>(); }
No casting required. Also, in your example, there is no return type. I assumed that you wanted to put void .
source share