Where to check for null in a call method or function?

If you need to check null before calling the function or inside the function itself?

+3
source share
4 answers

I would say in the call itself. Thus, you only check for zero in one place, not 5 places, if you call this function from 5 different points.

But this is not the right answer. It really depends on the function and what consequences it causes with a null argument.

+3
source

, , , ,

+1

. , .

+1

null , null . DRY, null ( ryeguy).

null , ( ) ( - NullPointerException ).

, , , : (i) ; (ii)

+1
source

Source: https://habr.com/ru/post/1705822/


All Articles