Back to Intellij Community

UnnecessarilyQualifiedStaticUsage

java/java-impl/resources/inspectionDescriptions/UnnecessarilyQualifiedStaticUsage.html

2025.3-rc-21016 B
Original Source

Reports usages of static members unnecessarily qualified with the class name.

Qualification with the class is unnecessary when the static member is available in a surrounding class or in a super class of a surrounding class. Such qualification may be safely removed.

Example:

class Foo {
    static void foo() {}
    static int x;

    void bar() {
      Foo.foo();
      System.out.println(Foo.x);
    }

    static void baz() { Foo.foo(); }
  }

After the quick-fix is applied:

class Foo {
    static void foo() {}
    static int x;

    void bar() {
      foo();
      System.out.println(x);
    }

    static void baz() { foo(); }
  }

Use the inspection options to toggle the reporting for:

  • Static fields access:
    void bar() { System.out.println(Foo.x); }

  • Calls to static methods:
    void bar() { Foo.foo(); }

Also, you can configure the inspection to only report static member usage in a static context. In this case, only static void baz() { Foo.foo(); } will be reported.