The conditional operator ?:
uses the boolean
value of one expression to decide which of the other two expressions should be evaluated . (See see JLS, Section 15.25, "Conditional Operator ? :
".)
...
The JLS-defined rules for determining the type of the result of a conditional expression (tabulated below) are quite complicated; programmers could be surprised by the type conversions required for expressions they have written.
...
The complexity of the rules that determine the result type of a conditional expression can lead to unintended type conversions. ThusConsequently, the second and third operands of each conditional expression should always have the same type. This recommendation also applies to boxed primitives.
...