Summary: | Ternary with cast produces different output than else-if | ||
---|---|---|---|
Product: | [Eclipse Project] JDT | Reporter: | David Wright <david.wright> |
Component: | Core | Assignee: | Srikanth Sankaran <srikanth_sankaran> |
Status: | VERIFIED INVALID | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | Olivier_Thomann, srikanth_sankaran |
Version: | 3.7 | ||
Target Milestone: | 3.7 M2 | ||
Hardware: | PC | ||
OS: | Windows XP | ||
Whiteboard: |
Description
David Wright
2010-08-16 05:52:30 EDT
I believe what you are observing is the correct behavior. See that javac also produces the same output. I'll dig up the relevant JLS section... (In reply to comment #1) I did wonder, when the output was the same in both Helios and Galileo. Twelve years of coding in Java and I still haven't got to the bottom of it! Here is the relevant text from JLS3 15.25 Conditional Operator ? : ... The type of a conditional expression is determined as follows: ... Otherwise, if the second and third operands have types that are convertible (§5.1.8) to numeric types, then there are several cases: ... Otherwise, binary numeric promotion (§5.6.2) is applied to the operand types, and the type of the conditional expression is the promoted type of the second and third operands. Note that binary numeric promotion performs unboxing conversion (§5.1.8) and value set conversion (§5.1.13). ... The chosen operand expression is then evaluated and the resulting value is converted to the type of the conditional expression as determined by the rules stated above. This conversion may include boxing (§5.1.7) or unboxing conversion. The operand expression not chosen is not evaluated for that particular evaluation of the conditional expression. Verified for 3.7M2 using I20100914-0100 |