homberghp commented on issue #8301:
URL: https://github.com/apache/netbeans/issues/8301#issuecomment-2821297836
Some testing in NB 24, 25, and 26-rc1 show that what happens
is
= before refactoring
```
class A extends C {
}
class B {
public static void main() {
final int b = 2;
new A() {
void m() {
System.out.println(b);
}
};
}
}
class C {
protected final int b = 1;
}
```
= after refactoring
```
class A extends C{
protected final int b = 1;
}
public class B {
public static void main() {
final int b = 2;
new A() {
protected final int b = 1; //<1>
void m() {
System.out.println(b); // <2>
}
};
}
}
class C {
}
```
So the refactoring does 2 things:
* push down the field to A.
* introduce a new field `<1>` in the anonymous sub-class of A (called B$1
because it is an anonylous inner class of B)
The later field hides the field in A proper.
This refactoring DOES NOT change behaviour.
A class, even an inner class always looks at its own fields first, either
directly declared fields or reachable (on-private)
fields of super classes. After that, the field in outer class may be
considered.
The `final int b` is a local variable in method `main`, and is only reached
when no field in A, or the subclass or any of its super classes hides b.
The fact that the anonymous inner class gets a field through the refactoring
surprises me but is a logical consequence of push-down when there are more
subclasses.
Doing it in the way NetBeans does things preserves semantics of the push
down which is a good thing.
I can imagine a feature request that when there are more levels of
subclassing, you would get the option to choose to what level would want to
push down.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists