...
Actually the null check is redundant, if the null check were removed, then the next call (s.equals("")
) would throw a NullPointerException
if s
was null. However, the explicit null check is good form, as it explicitly signifies the code's intention. More complex code may require explicit testing of invariants and appropriate throw statements.
...