Reputation: 11309
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
.
Upvotes: 0
Views: 291
Reputation: 13427
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
).
Upvotes: 2
Reputation: 79875
This fixes up the case where you've got a static method in one class, but you're calling it using the name of a subclass. So, the static method might be
SuperClass.someStaticMethod();
but you've referenced it as
SubClass.someStaticMethod();
Note that it's similar to another clean-up, where you call a static method, like myObject.someStaticMethod();
in place of TheClass.someStaticMethod();
. The part in parentheses indicates that it's the "access through a subtype" clean-up.
Upvotes: 1
Reputation: 108
You're calling your static variable/method through object instead of the class where it's defined. When it says 'by declaring type ' it means that you declared your variable/method as a class variable/method and you should call it by that.
Upvotes: 0