问题描述
当我在中思考
中的 Serializable
界面时,会出现一句话:
When I read the about the Serializable
interface in Thinking in java
, there is a sentence that says:
在:
所以如果我不喜欢首先调用 defaultWriteObject
,如果我在调用之前写了其他的东西,会有问题吗?我试过了,但似乎它在我的例子中仍然运作良好。那么如果有任何问题,它会在什么条件下发生?
So If I don't call defaultWriteObject
first, and if I write something else before that call, will there be any problem? I have tried it, but it seems that it still works well in my example. So If there is to be any problem, under what condition could it occur ?
推荐答案
Java对象序列化规范在这个问题上含糊不清:
Java Object Serialization Specification is vague on this subject:
这是一个给出了可能出现问题的示例案例。
Here's an old thread which gives an example case when problems might occur.
这是一个JBoss AS用另一个例子。
And here's a JBoss AS Jira ticket with another example.
这篇关于为什么在写入ObjectOutputStream时必须首先调用defaultWriteObject函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!