android - java的LinkedHashMap序列化传递之后,只能反序列化为HashMap
大家讲道理
大家讲道理 2017-04-17 17:12:41
0
3
1007

发送之前数据结构:

private LinkedHashMap<Integer, LinkedHashMap<Integer, Integer>> selected = new LinkedHashMap<>();

通过

Bundle bundle = new Bundle();
bundle.putSerializable("data", selected);

传递到下一个activity之后,使用

getIntent().getBundleExtra(G.BUNDLE).getSerializable("data")

只能得到HashMap类型的数据结构,HashMap<Integer, HashMap<Integer, Integer>>;
这是为什么呢?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(3)
大家讲道理

LinkedHashMap is a subclass of HashMap. Have you tried explicit type conversion?

阿神

Convert it into a json string, pass it and then convert it back.

PHPzhong

LinkedHashMap does not implement the serializable interface, and its parent class HashMap does. Therefore, it is deserialized into a HashMap and can be forced to perform explicit type conversion when used.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!