Inspectopedia Help

Instantiation of utility class

Reports instantiation of utility classes using the new keyword.

In utility classes, all fields and methods are static. Instantiation of such classes is most likely unnecessary and indicates a mistake.

Example:

class MyUtils { public static double cube(double x) { return x * x * x; } } class Main { public static void main(String[] args) { // Instantiation of utility class MyUtils utils = new MyUtils(); } }

To prevent utility classes from being instantiated, it's recommended to use a private constructor.

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023