Enforcing the Order of Condition Evaluation
To enforce the order of evaluation between two or more conditions, put them on the same line (that is, in one statement ending in a semicolon) joined by the logical operator &&
.
Be aware of some differences in execution when you combine conditions. For example, consider the following separate conditions. A null pointer exception might be thrown if concept.containedConcept
is null, if the second condition was checked before the first:
concept.containedConcept != null; concept.containedConcept.property == "test";
You can, however, combine the conditions as follows:
concept.containedConcept != null && concept.containedConcept.property == "test";
In this case, a null pointer exception is not thrown when concept.containedConcept
is null because it is always checked first.