Why explicitly throw a NullPointerException rather than letting it happen naturally?

后端 未结 9 1458
无人共我
无人共我 2020-12-12 13:40

When reading JDK source code, I find it common that the author will check the parameters if they are null and then throw new NullPointerException() manually. Why do they do

9条回答
  •  既然无缘
    2020-12-12 14:05

    It is intentional to protect further damage, or to getting into inconsistent state.

提交回复
热议问题