Why this matters
Classes with only private constructors cannot be instantiated outside their own scope, potentially making them dead code.
Classes with only private constructors cannot be instantiated outside their own scope, potentially making them dead code.
Classes with only private constructors cannot be instantiated outside their own scope, potentially making them dead code.
Side-by-side examples engineers can pattern-match during review.
public class MyClass // Noncompliant: the class contains only private constructors
{
private MyClass() { ... }
}public class MyClass // Compliant: the class contains at least one non-private constructor
{
public MyClass() { ... }
}public class MyClass // Noncompliant: the class contains only private constructors
{
private MyClass() { ... }
}public class MyClass // Compliant: the class contains at least one non-private constructor
{
public MyClass() { ... }
}From the same buckets as this rule.