2021-04-28 16:49:39 +02:00
|
|
|
Classes with only ``++private++`` constructors should be marked ``++final++`` to prevent any mistaken extension attempts.
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-04-28 16:49:39 +02:00
|
|
|
== Noncompliant Code Example
|
|
|
|
|
|
|
|
----
|
|
|
|
public class PrivateConstructorClass { // Noncompliant
|
|
|
|
private PrivateConstructorClass() {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int magic(){
|
|
|
|
return 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-04-28 16:49:39 +02:00
|
|
|
== Compliant Solution
|
|
|
|
|
|
|
|
----
|
|
|
|
public final class PrivateConstructorClass { // Compliant
|
|
|
|
private PrivateConstructorClass() {
|
|
|
|
// ...
|
|
|
|
}
|
|
|
|
|
|
|
|
public static int magic(){
|
|
|
|
return 42;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
2021-04-28 18:08:03 +02:00
|
|
|
|
2021-06-02 20:44:38 +02:00
|
|
|
|
|
|
|
ifdef::rspecator-view[]
|
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
|
|
|
include::comments-and-links.adoc[]
|
|
|
|
endif::rspecator-view[]
|