I would go for
"Something".equals(MyInput);
in this case if MyInput is null
then it won't throw NullPointerException
Here we are sure that the object on which equals()
is going to invoke is NOT NULL
.
And if you expect NullPointerException
from your code to take some decision or throw/wrap it, then go for first.
There is no performance impact
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…