Java: Why aren't NullPointerExceptions called NullReferenceExceptions?

后端 未结 5 2226
孤城傲影
孤城傲影 2020-11-30 07:45

Was this an oversight? Or is it to do with the JVM?

5条回答
  •  猫巷女王i
    2020-11-30 08:02

    I think that the answer is that we'll never really know the real answer.

    I suspect that some time before Java 1.0 was released, someone defined a class called NullPointerException. Either that person got the name wrong, or the terminology hadn't stabilized; i.e. the decision to use the term "reference" instead of "pointer" hadn't been made.

    Either way, it is likely that nobody noticed the inconsistency couldn't be fixed without breaking backwards compatibility. There are other minor inconsistencies like this if you look really hard. And some more serious issues that couldn't be fixed for the same reason.

    But this is just conjecture.

提交回复
热议问题