First take a look at the following sample code:
Parent.java
public class Parent...{
public void parentMethod() ...{
}
}
Ichild.java
public interface IChild ...{
void interfaceMethod();
}
Child.java
public class Child extends Parent implements IChild ...{
@Override
public void parentMethod() ...{
}
@Override
public void interfaceMethod() ...{
}
}
Because the code is simple, I don't explain it.
The above code can be compiled by jdk6
In Jdk5, compilation fails, and the output error message is as follows:
Child.java:7: Methods for methods that do not overwrite their parent classes
@Override
^
1 Error
The error message above says that the override annotation on line seventh of Child.java is not correct, because the method (Interfacemethod) is not a parent class method.
Of course, this method is actually a class implementation of the interface method, but the syntax of the jdk6 of the following can be passed, that is, java6 that the class overrides the parent class method and implementation interface method is called override, and Jdk5 do not think so, do not know this is the original Jdk5 bug, Or the original is that the coverage of the parent class method and the implementation of interface method is not the same, unknown. But from the Oo point of view, covering the parent class method and implementing interface methods can be considered override, because their purpose is the same, are for reuse, are a manifestation of polymorphism. This function can be seen from the support of the JDK6.
Almost forgot:
Standard Java API documentation Java5 is the same as Java6 's interpretation of override annotation
JAVA5:
Indicates that ' a method ' declaration is intended to override a, declaration in a. If A is annotated with the annotation type but does not override a superclass method, compilers are required to GE Nerate an error message.
JAVA6:
Indicates that ' a method ' declaration is intended to override a, declaration in a. If A is annotated with the annotation type but does not override a superclass method, compilers are required to GE Nerate an error message.
The two paragraphs are exactly the same, making it unclear that the JAVA6 document does not mention override's support for interface.