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

Javac accepts erroneous binary comparison operations

XMLWordPrintable

    • b98
    • Verified

      This code should not compile:

      class Main {
      public boolean func(Object obj) {
      return obj == 0;
      }
      }

      But javac (since JDK 7 accepts it).

      The following variant:

      class Main {
      public boolean func(Object obj) {
      return 0 == obj;
      }
      }

      should also not compile - but note that this was accepted since JDK 5.

      Relevant JLS section is 15.21. Javac seems to treat this as a reference comparison, but a reference comparison is only allowed when BOTH operands are reference types.

            emc Eric Mccorkle
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: