Pattern variable hides field
Reports pattern variables named identically to a field of a surrounding class. As a result of such naming, you may accidentally use the pattern variable when using the identically named field is intended.
A quick-fix is suggested to rename the variable.
Example:
class Pointless {
Point p = new Point();
public void test(Object a) {
if (a instanceof Point p) {
System.out.print("a is a point (" + p.x + ", " + p.y + ')');
} else {
System.out.print("p is a point (" + p.x + ", " + p.y + ')');
}
}
}- 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.
PatternVariableHidesField
New in 2022.2
You can suppress this inspection by placing the following comment marker before the code fragment where you no longer want messages from this inspection to appear:
//noinspection PatternVariableHidesFieldnote
Actual comment syntax will depend on the code language you are working with
More detailed instructions as well as other ways and options that you have can be found in the product documentation:
Inspection Details | |
|---|---|
By default bundled with: |