Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8029467

Widening of booleans causes bad results

    XMLWordPrintable

Details

    • b122
    • generic
    • generic
    • Verified

    Backports

      Description

        Widening of types allows widening of boolean to int. This causes undesirable results with both ternary operator and return values of functions. Both examples below print "1", when they should print "true":

        print((function (x) { return x ? true : 0 })(true))
        print((function (x) { if(x) { return true } else { return 0 } })(true))

        Attachments

          Issue Links

            Activity

              People

                attila Attila Szegedi
                attila Attila Szegedi
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: