11

我正在使用以下代码HashMap<String, String从 Parcel 中读取类型为 > 的地图:

in.readHashMap(HashMap.class.getClassLoader());

这似乎工作得很好,但我收到一个警告:

Type safety: The expression of type HashMap needs unchecked conversion to conform to Map<String,String>

有没有“正确”的方法来做到这一点,使用不同的类加载器?还是我应该选择@SuppressWarnings("unchecked")?

4

1 回答 1

8

Android 开发者文档Parcel.readHashMap()说:

readBundle(ClassLoader)改用(其数据必须使用writeBundle(Bundle).

所以也许你应该使用readBundle()andwriteBundle()代替。

于 2012-05-25T16:07:49.037 回答