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

javac accepts semantically invalid == test

XMLWordPrintable

    • generic
    • generic

      boolean b = ((Object)null == 3);
         should not compile since it's not a numerical equality test
         (JLS15.21.1) nor a boolean equality test (15.21.2) nor a
         reference equality test (15.21.3). Indeed, it does not compile.

      boolean b = (3 == (Object)null);
         should not compile for exactly the same reason, but does compile!
         I am told javac performs a boxing conversion followed by a
         widening reference conversion, which isn't a valid combination
         allowed under casting conversion (mentioned in 15.21.3), so I am
         not sure what javac is trying to do.

            ahe Peter Ahe
            ahe Peter Ahe
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: