A transient final field used as a lock is null

后端 未结 3 985
别跟我提以往
别跟我提以往 2021-01-05 11:15

The following code throws a NullPointerException.

import java.io.*;

public class NullFinalTest {
    public static void main(String[] args) thr         


        
3条回答
  •  误落风尘
    2021-01-05 12:07

    A transient final field used as a lock is null

    Here are few facts about the transient variable:

    - Transient keyword when used on an instance variable, will prevent that instance variable to be serialized.

    - On De-serialization, the transient variable get to their Default values.....

    Eg:

    • Object Reference Variable to null
    • int to 0
    • boolean to false, etc.......

    So thats the reason you are getting a NullPointerException, when deserializing it...

提交回复
热议问题