Why does Java have transient fields?

前端 未结 15 1958
旧时难觅i
旧时难觅i 2020-11-22 03:54

Why does Java have transient fields?

15条回答
  •  无人及你
    2020-11-22 04:45

    To allow you to define variables that you don't want to serialize.

    In an object you may have information that you don't want to serialize/persist (perhaps a reference to a parent factory object), or perhaps it doesn't make sense to serialize. Marking these as 'transient' means the serialization mechanism will ignore these fields.

提交回复
热议问题