Inspectopedia Help

Unnecessarily qualified static access

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.


class Foo { static void foo() {} static int x; void bar() {; System.out.println(Foo.x); } static void baz() {; } }

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() {; }

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

Inspection options

Here you can find the description of settings available for the Unnecessarily qualified static access inspection, and the reference of their default values.

Ignore unnecessarily qualified field accesses

Not selected

Ignore unnecessarily qualified method calls

Not selected

Only report qualified static access from a static context

Not selected

Inspection Details

By default bundled with:

IntelliJ IDEA 2024.1, Qodana for JVM 2024.1,

Can be installed with plugin:

Java, 241.16690

Last modified: 29 April 2024