TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - Java Coding Standard
Search

Rule:  Design1Checked automatically with code checker

Synopsis:Classes with only static methods should have a private constructor
Language:Java
Severity Level:3
Category:Design


Description:

If you have a class that has nothing but static methods, it allows either one instance or none at all. In either case a private constructor should be used. This also holds in case exactly one instance is allowed, because the Singleton pattern uses a private constructor.

Note that this doesn't apply to abstract classes, since their subclasses may well include non-static methods.

public class MaybeASingleton {
 public static void foo() {}
 public static void bar() {}
}