They are not associated with a short rating. In Java, A && Breturns false immediately when Aevaluated to false. It matters, for example. when it comes to Exceptionsor logical methods that are not pure functions.
You can try the following experiment:
public class Test {
public n = 0;
public boolean A() {
System.out.println("A");
return false;
}
public boolean B() {
System.out.println("B");
return true;
}
public boolean C() {
n++;
return true;
}
public boolean D() {
n = n*2;
return false;
}
public static void main(String[] args) {
Test test = new Test();
if (test.A() && test.B()) { System.out.println("true"); }
if (test.B() && test.A()) { System.out.println("true"); }
if (test.C() && test.D()){}
else {System.out.println(t.n);}
t.n = 0;
if (test.D() && test.C()){}
else {System.out.println(t.n);}
t.n = 0;
boolean c = test.C();
boolean d = test.D();
if (d && c){}
else {System.out.println(t.n);}
}
}
It shows the consequences of a short assessment associated with a side effect.
source
share