H2ONaCl H2ONaCl - 2 months ago 12
Java Question

Eclipse Java clean-up feature

Eclipse has an automatic Java clean up that is called:


change indirect access to static members to direct access (accesses through subtypes)"`


What does it mean?

Edit: Note that there is another one that is


change non-static access to static members using declaring type


so the subject of my inquiry has to be different from this.

These are in
Windows > Preferences > Java > CodeStyle > Clean-Up
which is almost impossible to find because it is under
Windows
.

Answer

Assume you have the class

class A {

    static int i;
}

Then

change indirect access to static members to direct access (accesses through subtypes)

refers to a case where you have another class

class B extends A {}

and write

B.i = 2;

in which case the cleanup will change it to

A.i = 2;

since (as I wrote in my comment) the static member will be accessed through the class in which it's declared (A), and not through a class inheriting it (B).

change non-static access to static members using declaring type

refers to a case where you write

A a = new A();
a.i = 2;

in which case the cleanup will change it to

A.i = 2;

since the static member will be accessed through the class (A) instead of through an instance of the class (a).