In this case it may seem that an element from the surrounding code is accessed, when in fact it is an access to a field from the superclass that the anonymous class extends.
To clarify the intent of the code, it is recommended to add an explicit
super
qualifier to the field access.
Example:
class First {
protected String test;
}
class Second {
void foo(String test) {
new First() {
{
System.out.println(test); // the field is accessed, not the parameter
}
};
}
}
After the quick-fix is applied:
class First {
protected String test;
}
class Second {
void foo(String test) {
new First() {
{
System.out.println(super.test);
}
};
}
}