Java Reference
In-Depth Information
Ingeneral,themisuseofthe assert statement forruntimecheckingratherthancheck-
ing for logical errors cannot be detected automatically.
Bibliography
[JLS 2013]
§14.10, “The assert Statement”
45. Use the same type for the second and third operands in conditional
expressions
Theconditional operator ?: usesthe boolean valueofitsfirstoperandtodecide whichof
the other two expressions will be evaluated. (See §15.25, “Conditional Operator ? : ,” of
the JLS [JLS 2013] .)
The general form of a Java conditional expression is operand1 ? operand2 : oper-
and3 .
If the value of the first operand ( operand1 ) is true , then the second operand ex-
pression ( operand2 ) is chosen.
If the value of the first operand is false , then the third operand expression ( oper-
and3 ) is chosen.
The conditional operator is syntactically right-associative. For example,
a?b:c?d:e?f:g is equivalent to a?b:(c?d:(e?f:g)) .
The JLS rules for determining the result type of a conditional expression (see Table
3-1 ) are complicated; programmers could be surprised by the type conversions required
for expressions they have written.
Search WWH ::




Custom Search