15.25. Conditional Operator ? :
The conditional operator ? :
uses the boolean value of one expression to decide which of two other expressions should be evaluated.
ConditionalExpression: ConditionalOrExpression ConditionalOrExpression ?
Expression :
ConditionalExpression
The conditional operator is syntactically right-associative (it groups right-to-left). Thus, a?b:c?d:e?f:g
means the same as a?b:(c?d:(e?f:g))
.
The conditional operator has three operand expressions. ?
appears between the first and second expressions, and :
appears between the second and third expressions.
The first expression must be of type boolean
or Boolean
, or a compile-time error occurs.
It is a compile-time error for either the second or the third operand expression ...
Get The Java® Language Specification, Java SE 7 Edition, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.