Consider this sample code:
public static void main(String[] args){
SomeObj obj = null;
if (obj == null || obj.getSomeMethod() == null) {
System.out.println("Obj is null");
}
if (result((x, y) -> x == null || y == null, obj, obj.getSomeMethod())) {
System.out.println("Obj is null");
}
}
private static <X, Y> boolean result(final BiPredicate<X, Y> p, final X argX, final Y argY){
return p.test(argX, argY);
}
In the first If condition I get the message "obj is null" but in the second If condition I get a NullPointerException. This BiPredicate should't be a short circuit operator (if the first condition is true don't bother evaluating the second one)?