search

Home  >  Q&A  >  body text

android - java的LinkedHashMap序列化传递之后,只能反序列化为HashMap

发送之前数据结构:

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>>;
这是为什么呢?

大家讲道理大家讲道理2770 days ago1021

reply all(3)I'll reply

  • 大家讲道理

    大家讲道理2017-04-17 17:14:41

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

    reply
    0
  • 阿神

    阿神2017-04-17 17:14:41

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

    reply
    0
  • PHPz

    PHPz2017-04-17 17:14:41

    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.

    reply
    0
  • Cancelreply