Java
Access to inherited field looks like access to element from surrounding code
Warning
New
Last modified: 03 December 2024Reports access to a superclass field from an anonymous, inner or local class, if a local variable, parameter, or field with the same name is available in the code surrounding the class. 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.
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 ambiguous;
}
class Second {
void foo(String ambiguous) {
new First() {
{
System.out.println(ambiguous); // the field is accessed, not the parameter
}
};
}
}
After the quick-fix is applied:
class First {
protected String ambiguous;
}
class Second {
void foo(String ambiguous) {
new First() {
{
System.out.println(super.ambiguous);
}
};
}
}
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
AmbiguousFieldAccess
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Java, 243.23126 |
Thanks for your feedback!
Was this page helpful?