!str.equals(null) will be
- always returns false if it does not throw an exception, and
- throws an exception if str is null
The point of null checking is to make sure that the link in this str code actually refers to the object. If this value is null, you cannot invoke any methods on it, including equals , without throwing a NullPointerException ... that the null checkpoint should avoid.
So !str.equals(null) leads to the fact that the very problems with null checks are designed to prevent and do not do what you think at all. Never do that.
source share