Inspectopedia Help

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:

class X { public String toString() { return "hello world"; } }

After the quick-fix is applied:

class X { @Override public String toString() { return "hello world"; } }

Configure the inspection:

  • Use the Ignore 'equals()', 'hashCode()' and 'toString()' option to ignore these java.lang.Object methods: equals(), hashCode(), and toString(). The risk that these methods will disappear and your code won't be compiling anymore due to the @Override annotation 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 @Override annotation, and not on overridden methods where one or more descendants are missing an @Override annotation.

This inspection only reports if the language level of the project or module is 5 or higher.

Inspection options

Option

Type

Default

Ignore 'equals()', 'hashCode()' and 'toString()' methods

Checkbox

true

Ignore methods in anonymous classes

Checkbox

false

Highlight method when its overriding methods do not all have the '@Override' annotation

Checkbox

true

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023