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

Widening of booleans causes bad results

XMLWordPrintable

    • b122
    • generic
    • generic
    • Verified

        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))

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

                Created:
                Updated:
                Resolved: