在Java 1.7上编译Java 1.5仍然有效吗?
我最近在我的一个项目中转到Java 7。我声称它可以在Java 1.5上运行,因为我在Java 6或7中没有任何依赖。但是在今天编译时我注意到了这一点:
I've recently moved to Java 7 in one of my projects. I claim that it can run on Java 1.5 simply because there's nothing I depend on that is in Java 6 or 7. However when compiling today I noticed this:
bootstrap class path not set in conjunction with -source 1.5
Google发现很少有关此警告的信息。这是否意味着您无法从Java 1.7编译到Java 1.5?
Google has found little information on this warning. Does this mean that you can't compile to Java 1.5 from Java 1.7?
此Oracle博客解释了警告:
This Oracle blog explains the warning:
http://blogs.oracle.com/ darcy / entry / bootclasspath_older_source
原因是,如果你没有为旧平台设置rt.jar,那么:
The reason is, that if you fail to set rt.jar for the older platform, then:
如果不采取第二步,javac将尽职尽责地使用旧的
语言规则与新库相结合,这可能导致
类因为对
不存在的方法的引用可以包含在旧平台上不起作用的文件。
If the second step is not taken, javac will dutifully use the old language rules combined with new libraries, which can result in class files that do not work on the older platform since references to non-existent methods can get included.