Interview : Java Equals

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

Leave a Comment