This interface only contains static fields and methods; consider making it a final class instead to prevent subclassing.


The problem

Interfaces should be used to define types. Using an interface as a collection of static methods and fields violates that, and can lead to confusing type hierarchies if the interface is then implemented to allow easy access to the constants.

Prefer using a public final class instead to prohibit subclassing.

public interface Constants {
  final float PI = 3.14159f;
public final class Constants {
  public static final float PI = 3.14159f;

  private Constants() {}

See Effective Java 3rd Edition ยง22: Use interfaces only to define types for more details.


Suppress false positives by adding the suppression annotation @SuppressWarnings("InterfaceWithOnlyStatics") to the enclosing element.