Serializable and transient

后端 未结 5 1755
無奈伤痛
無奈伤痛 2021-01-02 06:24

To make a class serializable we do the following:

class A implements Serializable {
    transient Object a;
}

And not this:



        
5条回答
  •  清酒与你
    2021-01-02 07:09

    So you're asking why you can't mark a class as not serializable (like a transient member)? Why wouldn't you just not mark class members of the not-to-serialize type as transient? Or use a serialization delegate for that class type when you do the serialization? It seems a little weird that you would want to tell Java to not do something at this level instead of telling it to do something.

提交回复
热议问题