why doesn't this code throw NullPointerException

后端 未结 5 1427
攒了一身酷
攒了一身酷 2021-01-11 12:42

I was just discussing about calling static methods using class name with my friend and tried out this code and expected it to throw NPE at runtime.but as it turn out it dint

5条回答
  •  悲&欢浪女
    2021-01-11 13:45

    method is static so it doesn't care about the One instance.

    One o = null;
    o.method();
    

    Is the same as:

    One.method();
    

提交回复
热议问题