rspec/rules/S1161/java/rule.adoc

58 lines
1.2 KiB
Plaintext
Raw Normal View History

== 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
A compliant method either overrides a parent method or implements an interface or abstract method.
2021-04-28 16:49:39 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
[source,java,diff-id=1,diff-type=noncompliant]
2021-04-28 16:49:39 +02:00
----
class ParentClass {
public boolean doSomething(){/*...*/}
2021-04-28 16:49:39 +02:00
}
class FirstChildClass extends ParentClass {
public boolean doSomething(){/*...*/} // Noncompliant
2021-04-28 16:49:39 +02:00
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
[source,java,diff-id=1,diff-type=compliant]
2021-04-28 16:49:39 +02:00
----
class ParentClass {
public boolean doSomething(){/*...*/}
2021-04-28 16:49:39 +02:00
}
class FirstChildClass extends ParentClass {
@Override
public boolean doSomething(){/*...*/} // Compliant
2021-04-28 16:49:39 +02:00
}
----
=== Exceptions
2021-04-28 16:49:39 +02:00
This rule does not raise issues when overriding methods from `Object` (eg: `equals()`, `hashCode()`, `toString()`, ...).
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Add the "@Override" annotation above this method signature
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]