Object with primitive type equality operator and Java Language specification

Rostislav Krasny rosti.bsd at gmail.com
Mon Jul 13 18:09:58 UTC 2015


Hi,

javac of JDK7 successfully compiles a code like following:

public class MainClass {

    private static Object getValue() {
        return 123;
    }

    public static void main(String[] args) {
        int num = 123;

        System.out.println(getValue() == num);
    }
}

I believe javac of other JDKs, starting from JDK5, also compile such a code
without any problem. However Eclipse and its Java compiler fails to compile
the Object with primitive type equality (getValue() == num) with an error
"Incompatible operand types Object and int". There is a bug report about
this in the Eclipse Bugzilla:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=405732

This bug was closed as NOT_ECLIPSE, i.e. developers of Eclipse Java
compiler believe their compiler do it right. Please read the discussion in
that bug report. Specifically Stephan Herrmann stated that Java Language
specification disallows compiling such a code. So is it a bug in the javac
compiler itself? Or maybe the JLS needs to be changed to conform to the
long ago adopted javac compiler implementation? Or there is the JLS
misunderstanding?

Thanks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20150713/b6db9e92/attachment.html>


More information about the compiler-dev mailing list