Where to check if an object is null or not?

前端 未结 13 1455
广开言路
广开言路 2020-12-17 10:18

Where do you check if an object that you are passing to a method is null or not?

Should an object need to be tested before calling a method? or within the method tha

相关标签:
13条回答
  • 2020-12-17 11:10

    I normally let my null checks be controlled by my expectations; if I expect something to be null or am unsure of it, I add a check. Otherwise I don't. Nulllpointer exceptions are among the easiest problems to track, so excessive sprinkling of checks bloats code. In the specific example I'd check nothing, because it's intutitive it's not null.

    0 讨论(0)
提交回复
热议问题