~/ learn/ java-from-zero/ cards/ Operators & precedence
1 of 4

Type a null-safe short-circuit check

Type a null-safe short-circuit check

Answer

if (name != null && name.length() > 0) {

Because && short-circuits, name.length() is only called when name != null is true — no NullPointerException.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/020ba840-e457-48e4-9a19-849721297442/flashcard utf-8 LF