Back to Intellij Community

UnqualifiedStaticUsage

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

2025.3-rc-2955 B
Original Source

Reports usage of static members that is not qualified with the class name.

This is legal if the static member is in the same class, but may be confusing.

Example:

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

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

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

After the quick-fix is applied:

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

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

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

Use the inspection settings to toggle the reporting for the following items:

  • static fields access
    void bar() { System.out.println(x); }

  • calls to static methods
    void bar() { foo(); }
    static void baz() { foo(); }

You can also configure the inspection to only report static member usage from a non-static context. In the above example, static void baz() { foo(); } will not be reported.