简体   繁体   中英

javac equality operators in java 7 and java 8

I have to write a little paper about "javac tools" in Java 8 for my class.

Here is something i dont understand. Oracle says, that in the new Java 8: "The type rules for equality operators in the Java Language Specification (JLS) Section 15.21 are now correctly enforced by the javac command."

"Whats new in Java 8": http://www.oracle.com/technetwork/java/javase/8-whats-new-2157071.html

Java language specification: http://docs.oracle.com/javase/specs/jls/se8/jls8-diffs.pdf

I don´t really understand that. I thought it worked just fine in Java 7. Does anybody have an idea what i missed? What wasn´t "enforced correctly" in Java 7?

If anybody has an answer, can you tell me where you found it, if you didnt find out by coincidence ;).

Here is a link to a bug report that reports one particular case where javac 7 would compile a == test which was not valid according to the JLS. Even though the bug is marked as fixed in 2010, discussions indicate that it was still manifesting in 2013.

In short, I would consider this "feature" of Java 8 to really be a bug fix. They haven't actually changed the language itself (as defined by the JLS), or added extra standard library functionality. They've just fixed an error that ideally would never have been there in the first place.

Given the time, this is likely a reference to JDK-8013357 :

This code should not compile:

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

But javac (since JDK 7 accepts it).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM