I know that Java has smart/lazy evaluation in this case:
public boolean isTrue() {
boolean a = false;
boolean b = true;
return b || (a &&
SE8 (JDK1.8) has introduced Lambda expressions, which can make lazy evaluations more transparent. Consider the statement in the main method of the following code:
@FunctionalInterface
public interface Lazy {
T value();
}
class Test {
private String veryLongMethod() {
//Very long computation
return "";
}
public static T coalesce(T primary, Lazy secondary) {
return primary != null? primary : secondary.value();
}
public static void main(String[] argv) {
String result = coalesce(argv[0], ()->veryLongMethod());
}
}
The called function coalesce returns the first given non-null value (as in SQL). The second parameter in its call is a Lambda expression. The method veryLongMethod() will be called only when argv[0] == null. The only payload in this case is inserting ()-> before the value to be lazily evaluated on demand.