What is null in c#, java?

后端 未结 9 1190
挽巷
挽巷 2020-12-15 23:09

Like... is it 0 like in C++? Or is it some \"special\" object? Or maybe something totally different?

-- EDIT --

I do know what it is, the

9条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 23:37

    Since Java and C# run on virtual machines, it does not matter what is used physically to represent null, and it is not necessarily the same across implementations.

    What matters is the behaviour of null, as defined in the language specification (see Dan's and MRFerocius' answers for details). Basically, it is a special value that variables of reference type can hold, and which cannot be dereferenced.

    BTW, as a reference point, the Java serialization spec use a single byte value 0x70 to represent a null reference.

提交回复
热议问题