All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.S1118.html Maven / Gradle / Ivy

The newest version!

Utility classes, which are a collection of static members, are not meant to be instantiated. Even abstract utility classes, which can be extended, should not have public constructors.

Java adds an implicit public constructor to every class which does not define at least one explicitly. Hence, at least one non-public constructor should be defined.

The following code:

class StringUtils { // Non-Compliant

  public static String concatenate(String s1, String s2) {
    return s1 + s2;
  }

}

should be refactored into:

class StringUtils { // Compliant

  private StringUtils() {
  }

  public static String concatenate(String s1, String s2) {
    return s1 + s2;
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy