rspec/rules/S3054/java/rule.adoc
2021-04-28 18:08:03 +02:00

28 lines
579 B
Plaintext

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.
== Noncompliant Code Example
----
public class MyClass {
private Foo foo;
public MyClass (Foo foo) {
super(); // Noncompliant
this.foo = foo;
}
----
== Compliant Solution
----
public class MyClass {
private Foo foo;
public MyClass (Foo foo) {
this.foo = foo;
}
----