java.io.ObjectOutputStream.write()
参数的非 Serializable
对象。 这样的调用将导致运行时异常。
该检查假定 java.util.Collection
和 java.util.Map
类型的对象为 Serializable
,除非它们声明的类型为非 Serializable
。
示例:
public class IWantToSerializeThis {
public static void main(String[] args) throws IOException {
try(var stream = new ObjectOutputStream(Files.newOutputStream(Paths.get("output")))) {
// 警告 -- 将会失败并抛出 NotSerializableException
stream.writeObject(new IWantToSerializeThis());
}
}
}