gpt4 book ai didi

Java 序列化 : Must E be serializable in ArrayList?

转载 作者:搜寻专家 更新时间:2023-10-31 19:55:34 25 4
gpt4 key购买 nike

我有以下类包含下面指定的字段。我的问题是,Admin、Worker 和我所有其他自定义类是否必须实现 Serializable 才能使 MyClass 实现可序列化?

public class MyClass implements java.io.Serializable {
private static final long serialVersionUID = 1L;
ArrayList<Admin> admins;
ArrayList<Worker> workers;
ArrayList<Manager> managers;
ArrayList<Secretary> secretaries;
ArrayList<Category> categories;
HashMap<Issue, HashMap<Category,Manager>> ManagedIssues;
private static MyClass instance;
...
}

最佳答案

My question is, must Admin, Worker and all my other self-defined classes implement Serializable for MyClass to be Serializable?

是的。他们必须是。

ArrayList 默认已经实现了Serializable接口(interface)。但是您需要为您使用的类型实现 Serializable 接口(interface)。

Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable.

关于Java 序列化 : Must E be serializable in ArrayList<E>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20765534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com