What classloader to use with Parcel.readHashMap?

android, classloader, generics, java, parcelable

Solution

The Android developer documentation for `Parcel.readHashMap()` says:

Please use `readBundle(ClassLoader)` instead (whose data must have been written with `writeBundle(Bundle)`.

So maybe you should be using `readBundle()` and `writeBundle()` instead.

Problem

I'm using the following code to read a map of type `HashMap<String, String`> from a Parcel: ``` in.readHashMap(HashMap.class.getClassLoader()); ``` This seems to work just fine, but I get a warning: ``` Type safety: The expression of type HashMap needs unchecked conversion to conform to Map<String,String> ``` Is there a "right" way to do this, use a different class loader? Or should I just go with `@SuppressWarnings("unchecked"`)?

Original source