tertiary operator error casting Float to Object
Alex Buckley
alex.buckley at oracle.com
Sat Sep 16 00:04:04 UTC 2023
It would have been helpful to explain what your typo was.
Your original mail:
Expected Result: isInt true, temp = 60.0
Actual Result: isInt true, temp = 60
Your updated mail (below):
Expected Result: isInt true, temp = 60
Actual Result: isInt true, temp = 60.0
Your updated mail is mistaken about the expected result. The expected
result is 60.0 because the type of ?Integer:Float is float. If you find
a JDK that doesn't give 60.0, let us know.
Alex
On 9/15/2023 4:23 PM, Liangtao wrote:
> Sorry for the typo (now fixed)
>
> On Fri, Sep 15, 2023 at 4:21 PM Liangtao <gliangtao at gmail.com
> <mailto:gliangtao at gmail.com>> wrote:
>
> The following code always output incorrect casting result:
>
> // BEGIN Bug.java code
> public class Bug {
> public static void main(String[] args) {
> float temp = 60.0f;
> boolean isInt = true;
> Object o = isInt ? Integer.valueOf((int)temp) :
> Float.valueOf(temp);
> System.out.println("isInt " + isInt + ", temp = " + o);
> }
> }
> // END Bug.java code
>
> Steps to reproduce:
> $ javac Bug.java && java Bug
>
> Actual Result:
>
> isInt true, temp = 60.0
>
>
> Expected Result:
>
> isInt true, temp = 60
>
>
More information about the compiler-dev
mailing list