Details
-
Type:
Code Smell Detection
-
Status: Active
-
Resolution: Unresolved
-
Labels:
-
Message:Make this class "final" or add a public constructor.
-
Default Severity:Minor
-
Impact:Low
-
Likelihood:Low
-
Covered Languages:Java
-
Remediation Function:Constant/Issue
-
Constant Cost:5min
-
Analysis Scope:Main Sources
-
Checkstyle:FinalClass
-
PMD:ClassWithOnlyPrivateConstructorsShouldBeFinal
Description
Classes with only private constructors should be marked final to prevent any mistaken extension attempts.
Noncompliant Code Example
public class PrivateConstructorClass { // Noncompliant private PrivateConstructorClass() { // ... } public static int magic(){ return 42; } }
Compliant Solution
public final class PrivateConstructorClass { // Compliant private PrivateConstructorClass() { // ... } public static int magic(){ return 42; } }
Attachments
Issue Links
- is implemented by
-
SONARJAVA-1144 Rule: S2974 Classes without "public" constructors should be "final"
-
- Closed
-