
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
72 lines
1.3 KiB
Plaintext
72 lines
1.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
When an inner class extends another class, and both its outer class and its parent class have a method with the same name, calls to that method can be confusing. The compiler will resolve the call to the superclass method, but maintainers may be confused, so the superclass method should be called explicitly, using ``++super.++``.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
public class Parent {
|
|
public void foo() { ... }
|
|
}
|
|
|
|
public class Outer {
|
|
|
|
public void foo() { ... }
|
|
|
|
public class Inner extends Parent {
|
|
|
|
public void doTheThing() {
|
|
foo(); // Noncompliant; was Outer.this.foo() intended instead?
|
|
// ...
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
public class Parent {
|
|
public void foo() { ... }
|
|
}
|
|
|
|
public class Outer {
|
|
|
|
public void foo() { ... }
|
|
|
|
public class Inner extends Parent {
|
|
|
|
public void doTheThing() {
|
|
super.foo();
|
|
// ...
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Prefix this call to "xxx" with "super.".
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 27 Jan 2015, 20:15:19 Freddy Mallet wrote:
|
|
+1 to activate this rule by default.
|
|
|
|
endif::env-github,rspecator-view[]
|