Why does Java have transient fields?

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

Why does Java have transient fields?

15条回答
  •  死守一世寂寞
    2020-11-22 04:25

    Serialization systems other than the native java one can also use this modifier. Hibernate, for instance, will not persist fields marked with either @Transient or the transient modifier. Terracotta as well respects this modifier.

    I believe the figurative meaning of the modifier is "this field is for in-memory use only. don't persist or move it outside of this particular VM in any way. Its non-portable". i.e. you can't rely on its value in another VM memory space. Much like volatile means you can't rely on certain memory and thread semantics.

提交回复
热议问题