使用android包时,为什么序列化堆栈反序列化为ArrayList?

And*_*ett 10 serialization android bundle

连载:

Bundle activityArguments = new Bundle();
Stack<Class<? extends WizardStep>> wizardSteps = new Stack<Class<? extends WizardStep>>();
        wizardSteps.push(CreateAlarmStep5View.class);
        wizardSteps.push(CreateAlarmStep4View.class);
        wizardSteps.push(CreateAlarmStep3View.class);
        wizardSteps.push(CreateAlarmStep2View.class);
        wizardSteps.push(CreateAlarmStep1View.class);

        activityArguments.putSerializable("WizardSteps", wizardSteps);
Run Code Online (Sandbox Code Playgroud)

Deserialisation:

Stack<Class<? extends WizardStep>> wizardSteps = 
(Stack<Class<? extends WizardStep>>) getIntent().getExtras().getSerializable("WizardSteps");
Run Code Online (Sandbox Code Playgroud)

例外:

12-20 23:19:45.698:E/AndroidRuntime(12145):引起:java.lang.ClassCastException:java.util.ArrayList无法强制转换为java.util.Stack

Max*_*tin 11

它已知的bug.我很惊讶它仍然存在.

使用通用容器,如:

public class SerializableHolder implements Serializable {
private Serializable content;
public Serializable get() {
    return content;
}
public SerializableHolder(Serializable content) {
    this.content = content;
 }
}
Run Code Online (Sandbox Code Playgroud)

如果使用GSON库,则将Stack转换为String,并将其用作Bundle的单个String,而不使用Serialize.它应该工作.