Wiki Markup |
---|
The conditional operator {{?:}} uses the {{boolean}} value of one expression to decide which of the other two expressions should be evaluated \[[JLS 2005|AA. JavaBibliography#JLS References#JLS 05]\]. The conditional operator is syntactically right-associative. For instance {{a?b:c?d:e?f:g}} is equivalent to {{a?b:(c?d:(e?f:g))}}. |
...
Wiki Markup |
---|
This noncompliant code example uses boxed and unboxed primitives of different types in the conditional expression. Consequently, the {{Integer}} object is auto-unboxed to its primitive type {{int}} and coerced to the primitive {{float}}. This results in loss of precision. \[[Findbugs 2008|AA. JavaBibliography#Findbugs References#Findbugs 08]\] (sic) |
Code Block | ||
---|---|---|
| ||
public class Expr { public static void main(String[] args) { Integer i = Integer.MAX_VALUE; float f = 0; System.out.print(true ? i : f); } } |
...
Wiki Markup |
---|
\[[JLS 2005|AA. Java References#JLSBibliography#JLS 05]\] [Section 15.25, Conditional Operator ? :|http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.25] \[[Bloch 2005|AA. Java References#BlochBibliography#Bloch 05]\] Puzzle 8: Dos Equis \[[Findbugs 2008|AA. Java References#FindbugsBibliography#Findbugs 08]\] "Bx: Primitive value is unboxed and coerced for ternary operator" |
...