I am using eclipse , when I use shortcut to generate override implementations , there is an override annotation up there , I am using JDK 6 , this is all right , but under JDK 5 this annotation will cause an error, so I want to ask , if this annotation is completely useless ? Will compiler do some kind of optimization using this annotation ?
Share
As others have pointed out, the
@Overrideannotation is really a compiler directive that instructsjavacto scream if a method annotated with@Overridedoes not actually override a method in its parent class (e.g. you’re actually overloading because you’ve decided to change the method signature or you misspell the method name).Under JDK 5, directly implementing a method from an interface is not considered overriding that method and is considered an error if annotated with
@Override.In part due to user feedback that this was a really confusing behaviour, JDK 6 changed this behaviour and does consider it correct to annotate a method you implement from an interface with
@Override.