rspec/rules/S3054/java/rule.adoc

36 lines
740 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
Each constructor must first invoke a parent class constructor, but it doesn't always have to be done explicitly. If the parent class has a reachable, no-args constructor, a call to it will be inserted automatically by the compiler. Thus, calls to ``++super()++`` can be omitted.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
public class MyClass {
private Foo foo;
public MyClass (Foo foo) {
super(); // Noncompliant
this.foo = foo;
}
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
public class MyClass {
private Foo foo;
public MyClass (Foo foo) {
this.foo = foo;
}
----
ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)
include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]