59 lines
1.2 KiB
Plaintext
59 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
While not mandatory, using the `@Override` annotation on compliant methods improves readability by making it explicit that methods are overriden.
|
|
|
|
A compliant method either overrides a parent method or implements an interface or abstract method.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
class ParentClass {
|
|
public boolean doSomething(){/*...*/}
|
|
}
|
|
class FirstChildClass extends ParentClass {
|
|
public boolean doSomething(){/*...*/} // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
class ParentClass {
|
|
public boolean doSomething(){/*...*/}
|
|
}
|
|
class FirstChildClass extends ParentClass {
|
|
@Override
|
|
public boolean doSomething(){/*...*/} // Compliant
|
|
}
|
|
----
|
|
|
|
|
|
=== Exceptions
|
|
|
|
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)
|
|
|
|
=== on 29 Jul 2013, 15:51:56 Freddy Mallet wrote:
|
|
Is implemented by \http://jira.codehaus.org/browse/SONARJAVA-249
|
|
|
|
endif::env-github,rspecator-view[]
|