What is null in Java?

后端 未结 14 1367
陌清茗
陌清茗 2020-11-21 20:49

What is null?

Is null an instance of anything?

What set does null belong to?

How is it represented in the me

14条回答
  •  爱一瞬间的悲伤
    2020-11-21 21:14

    Bytecode representation

    Java's null has direct JVM support: three instructions are used to implement it:

    • aconst_null: e.g. to set a variable to null as in Object o = null;
    • ifnull and ifnonnull: e.g. to compare an object to null as in if (o == null)

    Chapter 6 "The Java Virtual Machine Instruction Set " then mentions the effects of null on other instructions: it throws a NullPointerException for many of them.

    2.4. "Reference Types and Values" also mentions null in generic terms:

    A reference value may also be the special null reference, a reference to no object, which will be denoted here by null. The null reference initially has no run-time type, but may be cast to any type. The default value of a reference type is null.

提交回复
热议问题