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

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.14841

Last modified: 12 March 2024