且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

有关Java 8向后兼容性的问题:JDK中的新方法

更新时间:2023-09-14 20:30:52

  1. 因为即使有这些选项,您仍在针对Java 8类进行编译. JDK不知道哪种方法出现在哪个版本的JDK中.所有这些选项的作用是告诉编译器在您正在编译的代码中仅接受Java 7语法,并生成Java 7字节码.您将必须传递实际链接到JDK 7类(使用-bootclasspath选项)以进行交叉编译.

  1. because even with these options, you're still compiling against the Java 8 classes. The JDK doesn't have any idea which methods appeared in what version of the JDK. All these options do is tell the compiler to accept only Java 7 syntax in the code you're compiling, and to generate Java 7 bytecode. You would have to pass actually link to the JDK 7 classes (using the -bootclasspath option) to cross-compile.

是的,这是一个问题.并不是很大,拥有所有新默认方法的好处比拥有一些罕见的非编译代码的不便更为重要.

Yes, it's a problem. Not huge, and the benefit of having all thses new default methods is more important than the inconvenience of having some rare non-compiling code.