Are there any specific examples of backward incompatibilities between Java versions?

后端 未结 14 676
孤城傲影
孤城傲影 2020-12-02 12:28

Have there been incompatibilities between Java releases where Java source code/Java class files targeting Java version X won\'t compile/run under version Y (where Y > X) ?

相关标签:
14条回答
  • 2020-12-02 12:39

    As Sean Reilly said, a new method can break your code. Besides the simple case that you have to implement a new method (this will produce a compiler warning) there is a worst case: a new method in the interface has the same signature as a method you do already have in your class. The only hint from the compiler is a warning that the @Override annotation is missing (Java 5 for classes, the annotation is supported for interfaces in Java 6 but optional).

    0 讨论(0)
  • 2020-12-02 12:41

    See report on API changes for the JRE class library here: http://abi-laboratory.pro/java/tracker/timeline/jre/

    The report includes backward binary- and source-compatibility analysis of Java classes.

    The report is generated by the japi-compliance-checker tool.

    ...

    Another interesting analysis for JDK 1.0-1.6 you can find at Japitools JDK-Results page.

    0 讨论(0)
  • 2020-12-02 12:41

    From personal experience, we had some AWT/Swing text fields embedded in a SWT_AWT frame in 1.5, that ceased to be editable after upgrading to 1.6.

    0 讨论(0)
  • 2020-12-02 12:44

    I have not tried it but in theory this would work in Java 1.1 and break in Java 1.2. (More info here)

    public class Test {
        float strictfp = 3.1415f;
    }
    
    0 讨论(0)
  • 2020-12-02 12:46

    The following will compile under Java 1.4 but not Java 1.5 or later.

    (Java 5 introduced 'enum' as a keyword. Note: it will compile in Java 5 if the "-source 1.4" option is provided.)

    public class Example {
        public static void main(String[] args) {
            String enum = "hello";
        }
    }
    
    0 讨论(0)
  • 2020-12-02 12:47

    Between 1.3 and 1.4 the interpretation of Long.parseLong(String) handled the empty string differently. 1.3 returns a 0 value, whereas 1.4 throws a NumberFormatException.

    Recompiles aren't needed, but working code stopped working if it relied on the 1.3 behaviour.

    0 讨论(0)
提交回复
热议问题