43 lines
831 B
Plaintext
43 lines
831 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;
|
|
}
|
|
----
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
include::message.adoc[]
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|