Missing '@Override' annotation
Reports methods overriding superclass methods but are not annotated with @java.lang.Override.
Annotating methods with @java.lang.Override improves code readability since it shows the intent. In addition, the compiler emits an error when a signature of the overridden method doesn't match the superclass method.
Example:
After the quick-fix is applied:
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
override- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Configure the inspection:
Use the Ignore 'equals()', 'hashCode()' and 'toString()' option to ignore these
java.lang.Objectmethods:equals(),hashCode(), andtoString(). The risk that these methods will disappear and your code won't be compiling anymore due to the@Overrideannotation is relatively small.Use the Ignore methods in anonymous classes option to ignore methods in anonymous classes.
Disable the Highlight method when its overriding methods do not all have the '@Override' annotation option to only warn on the methods missing an
@Overrideannotation, and not on overridden methods where one or more descendants are missing an@Overrideannotation.
This inspection depends on the Java feature 'Annotations', which is available since Java 5.
Inspection options
Here you can find the description of settings available for the Missing '@Override' annotation inspection, and the reference of their default values.
- Ignore 'equals()', 'hashCode()' and 'toString()' methods
Default value:
Selected- Ignore methods in anonymous classes
Default value:
Not selected- Highlight method when its overriding methods do not all have the '@Override' annotation
Default value:
Selected
Suppressing Inspection
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |