Why is “null” present in C# and Java?

前端 未结 25 1935
别那么骄傲
别那么骄傲 2020-11-29 22:09

We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException.

Is there a reason why \"null\" has even been included in the l

25条回答
  •  死守一世寂寞
    2020-11-29 22:44

    Null do not cause NullPointerExceptions...

    Programers cause NullPointerExceptions.

    Without nulls we are back to using an actual arbitrary value to determine that the return value of a function or method was invalid. You still have to check for the returned -1 (or whatever), removing nulls will not magically solve lazyness, but mearly obfuscate it.

提交回复
热议问题