2023-05-03 11:06:20 +02:00
== Why is this an issue?
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
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
public class PrivateConstructorClass { // Noncompliant
private PrivateConstructorClass() {
// ...
}
public static int magic(){
return 42;
}
}
----
2021-04-28 18:08:03 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
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
2021-06-03 09:05:38 +02:00
ifdef::env-github,rspecator-view[]
2021-09-20 15:38:42 +02:00
'''
== Implementation Specification
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== Message
Make this class "final" or add a public constructor.
2021-09-20 15:38:42 +02:00
2021-06-08 15:52:13 +02:00
'''
2021-06-02 20:44:38 +02:00
== Comments And Links
(visible only on this page)
2023-05-25 14:18:12 +02:00
=== on 27 May 2015, 08:42:14 Freddy Mallet wrote:
My personal feedback:
* I would not activate this rule by default as it is controversial -> some guys are going to say that it's useless to flag such classes as final as any way it's by design not possible to extend them
* Due to the previous point I would associate this rule to the SQALE characteristic "Maintainability > Understandability" and not "Changeability - Architecture related changeability"
=== on 27 May 2015, 19:16:27 Ann Campbell wrote:
Rule updated
=== on 1 Jun 2015, 13:06:32 Nicolas Peru wrote:
ok.
2021-06-03 09:05:38 +02:00
endif::env-github,rspecator-view[]