~/ 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/bf4a596f-f0da-4a21-bcba-f2e1f61f1721/flashcard utf-8 LF