2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2024-07-10 15:49:32 +02:00
|
|
|
While not mandatory, using the `@Override` annotation on compliant methods improves readability by making it explicit that methods are overridden.
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-01 16:39:18 +02:00
|
|
|
A compliant method either overrides a parent method or implements an interface or abstract method.
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-09 16:36:32 +02:00
|
|
|
[source,java,diff-id=1,diff-type=noncompliant]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
class ParentClass {
|
2023-06-01 16:39:18 +02:00
|
|
|
public boolean doSomething(){/*...*/}
|
2021-04-28 16:49:39 +02:00
|
|
|
}
|
|
|
|
class FirstChildClass extends ParentClass {
|
2023-06-01 16:39:18 +02:00
|
|
|
public boolean doSomething(){/*...*/} // Noncompliant
|
2021-04-28 16:49:39 +02:00
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-09 16:36:32 +02:00
|
|
|
[source,java,diff-id=1,diff-type=compliant]
|
2021-04-28 16:49:39 +02:00
|
|
|
----
|
|
|
|
class ParentClass {
|
2023-06-01 16:39:18 +02:00
|
|
|
public boolean doSomething(){/*...*/}
|
2021-04-28 16:49:39 +02:00
|
|
|
}
|
|
|
|
class FirstChildClass extends ParentClass {
|
|
|
|
@Override
|
2023-06-01 16:39:18 +02:00
|
|
|
public boolean doSomething(){/*...*/} // Compliant
|
2021-04-28 16:49:39 +02:00
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Exceptions
|
2021-04-28 16:49:39 +02:00
|
|
|
|
2023-06-01 16:39:18 +02:00
|
|
|
This rule does not raise issues when overriding methods from `Object` (eg: `equals()`, `hashCode()`, `toString()`, ...).
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-09-20 15:38:42 +02:00
|
|
|
|
|
|
|
'''
|
|
|
|
== Implementation Specification
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== Message
|
|
|
|
|
|
|
|
Add the "@Override" annotation above this method signature
|
|
|
|
|
2021-09-20 15:38:42 +02:00
|
|
|
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-02 20:44:38 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2024-07-22 15:13:13 +02:00
|
|
|
include::../comments-and-links.adoc[]
|
2023-05-25 14:18:12 +02:00
|
|
|
|
2021-06-03 09:05:38 +02:00
|
|
|
endif::env-github,rspecator-view[]
|