Java: “attempting to assign weaker access privilege error” (Compiling JDK 1.6 Source with 1.8)
使用Gradle,我们正在尝试编译遗留Java代码,该代码是使用JDK 1.8编译器为JDK 1.6开发的。
在某个时候,编译过程因错误
退出
attempting to assign weaker access privileges; was public
(错误原因很明显:我们在抽象类中有一个方法,该方法声明为public,但是实现类将其声明为protected。)
使用JDK 1.6进行编译,对此我们没有任何问题。
现在由于多种原因,我们不得不使用Java 8来编译代码,从而使我们遇到了这个问题。
我们已经在构建时尝试了项目设置
目前,重构整个产品代码(预计会有更多类似错误)是不可行的,因此我们正在寻找一种使用新JDK构建旧代码的解决方案。
对此有任何帮助吗?
您的系统曾经使用过Java 1.6的事实的唯一解释是,超类中的方法访问已更改为
Java语言规范1.6在第344页提供了以下说明:
if the package points defines the
class Point :
1
2
3
4
5
6
7used by the Test program:
1
2
3
4
5
6
7
8
9then these classes compile and Test executes to produce the output:
1 TestIf the method
Point is changed to bepublic , and then only thePoint class is recompiled, and then executed with the previously existing binary forTest then no linkage error occurs, even though it is improper, at compile time, for a public method to be overridden by a protected method (as shown by the fact that the classTest could not be recompiled using this newPoint class unless print were changed to bepublic .) (emphasis added)
如果必须使用Java 1.8编译器重新创建确切的行为,请将超类中的可访问性更改为