Is there a static analysis tool that can enforce usage of the @Override annotation consistently that can be run outside of an IDE? CheckStyle has a MissingOverride check but it only applies to methods that use the @inheritDoc Javadoc tag. I'm looking for a tool that can be run in a new build configuration on a continuous integration machine.
@Override @Override annotation informs the compiler that the element is meant to override an element declared in a superclass. Overriding methods will be discussed in Interfaces and Inheritance. While it is not required to use this annotation when overriding a method, it helps to prevent errors.
If you don't use the annotation, the sub-class method will be treated as a new method in the subclass (rather than the overriding method). 2) It improves the code's readability.
The @Override annotation indicates that the child class method is over-writing its base class method. It extracts a warning from the compiler if the annotated method doesn't actually override anything. It can improve the readability of the source code.
It is not necessary, but it is highly recommended. It keeps you from shooting yourself in the foot. It helps prevent the case when you write a function that you think overrides another one but you misspelled something and you get completely unexpected behavior.
PMD now has a MissingOverride rule.
What about PMD or Findbugs? PMD enables that you can even write your own rule (if it isn't disposable in the default rule set).
https://pmd.github.io/pmd-6.3.0/pmd_userdocs_extending_writing_pmd_rules.html
I am using Sonar wich gives me the warnings but most importantly I am using eclipse (and so does my team) and I have set an option "add missing @Overrides" to be done on save action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With