The conditional operator ?:
uses the boolean
value of its first operand to decide which of the other two expressions will be evaluated. (See §15§15.25, "Conditional Operator ? :
" of the Java Language Specification [JLS 2005].)
...
Rule | Operand 2 | Operand 3 | Resultant type |
---|---|---|---|
1 | type T | type T | type T |
2 |
|
|
|
3 |
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
|
|
7 |
|
|
|
8 |
|
|
|
9 |
|
|
|
10 | other numeric | other numeric | promoted type of the 2nd and 3rd operands |
11 | T1 = boxing conversion (S1) | T2 = boxing conversion(S2) | apply capture conversion to lub(T1,T2) |
See §5§5.1.7, "Boxing Conversion"; §5§5.1.10, "Capture Conversion"; and §15§15.12.2.7, "Inferring Type Arguments Based on Actual Arguments" of the Java Language Specification for additional information on the final table entry.
...
Wiki Markup |
---|
\[[Bloch 2005|AA. Bibliography#Bloch 05]\] Puzzle 8: Dos Equis \[[Findbugs 2008|AA. Bibliography#Findbugs 08]\] "Bx: Primitive value is unboxed and coerced for ternary operator" \[[JLS 2005|AA. Bibliography#JLS 05]\] [§15§15.25|http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.25], "Conditional Operator {{? :}}" |
...
EXP11-J. Never dereference null pointers 02. Expressions (EXP) 03. Numeric Types and Operations (NUM)