How do I address unchecked cast warnings?

后端 未结 23 1184
醉梦人生
醉梦人生 2020-11-22 03:06

Eclipse is giving me a warning of the following form:

Type safety: Unchecked cast from Object to HashMap

This is from a call to

23条回答
  •  别跟我提以往
    2020-11-22 03:34

    I may have misunderstood the question(an example and a couple of surrounding lines would be nice), but why don't you always use an appropriate interface (and Java5+)? I see no reason why you would ever want to cast to a HashMap instead of a Map. In fact, I can't imagine any reason to set the type of a variable to HashMap instead of Map.

    And why is the source an Object? Is it a parameter type of a legacy collection? If so, use generics and specify the type you want.

提交回复
热议问题