Why does Java have transient fields?

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

Why does Java have transient fields?

15条回答
  •  生来不讨喜
    2020-11-22 04:33

    As per google transient meaning == lasting only for a short time; impermanent.

    Now if you want to make anything transient in java use transient keyword.

    Q: where to use transient?

    A: Generally in java we can save data to files by acquiring them in variables and writing those variables to files, this process is known as Serialization. Now if we want to avoid variable data to be written to file, we would make that variable as transient.

    transient int result=10;
    

    Note: transient variables cannot be local.

提交回复
热议问题