Here is some sample java code that is illegal under 1.5, if I understand correctly
(since @Override could not be used for overrides of interface methods until java 1.6):
public class A {
public static interface MyInterface {
public void myInterfaceMethod();
}
public static class MyClass implements MyInterface {
@Override public void myInterfaceMethod() {}
}
}
I want to find all such 1.5-incompatibilities in my source code, so I installed a java1.5-capable compiler on my ubuntu linux machine:
sudo apt install openjdk-8-jdk
JAVAROOT=/usr/lib/jvm/java-1.8.0-openjdk-amd64
${JAVAROOT}/bin/javac -version
# javac 1.8.0_232
and compiled the above java source code:
${JAVAROOT}/bin/javac -source 1.5 -Xlint:all -Xlint:-options A.java
I expected the above java code to be rejected. But it apparently compiled successfully, in spite of the illegality under 1.5.
What's going on? Am I misunderstanding the 1.5 rules about @Override?
Or am I misunderstanding what -source 1.5 is supposed to do?
FWIW, I notice that -source 1.4 does give the expected error:
${JAVAROOT}/bin/javac -source 1.4 -Xlint:all -Xlint:-options A.java
A.java:6: error: annotations are not supported in -source 1.4
@Override public void myInterfaceMethod() {}
^
(use -source 5 or higher to enable annotations)
1 error