Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What classloader to use with Parcel.readHashMap?

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")?

like image 299
hdort Avatar asked May 25 '12 15:05

hdort


1 Answers

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.

like image 71
David Wasser Avatar answered Oct 01 '22 22:10

David Wasser