tertiary operator error casting Float to Object

Liangtao gliangtao at gmail.com
Fri Sep 15 23:23:15 UTC 2023


Sorry for the typo (now fixed)

On Fri, Sep 15, 2023 at 4:21 PM Liangtao <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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/compiler-dev/attachments/20230915/9bdaee24/attachment.htm>


More information about the compiler-dev mailing list