Community
Participate
Working Groups
Both in Java and many other programming languages the boolean expressions are evaluated 'lazily'. If, for example, in expression '(a && b)', a is false, then b is not evaluated. This lets write less code in many cases. Compare for example: if (file != null) { if (file.exist) return true; } with return (file != null && file.exist) In Xtend2 all parts of complex boolean expressions are evaluated. The following Xtend function: boolean fileExists (File file) { file != null && file.exists } generates the following Java code: public boolean fileExists(final File file) { final File typeConverted_file = (File)file; boolean _operator_notEquals = ObjectExtensions.operator_notEquals(typeConverted_file, null); boolean _exists = file.exists(); boolean _operator_and = BooleanExtensions.operator_and(_operator_notEquals, _exists); return _operator_and; } At runtime a NPE is thrown if the input argument file is null.
*** This bug has been marked as a duplicate of bug 342424 ***