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

后端 未结 9 1453
无人共我
无人共我 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:07

    It is so you will get the exception as soon as you perpetrate the error, rather than later on when you're using the map and won't understand why it happened.

提交回复
热议问题