summaryrefslogtreecommitdiff
path: root/plugins/InspectionGadgets/src/inspectionDescriptions/AmbiguousFieldAccess.html
blob: b0f698b74e7ea2963196b794200a9cd0c3e21103 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<html>
<body>
Reports field accesses of a super class where a local variable, parameter or field of the same name is available
in the surrounding class. In this case a cursory reader of the code may think that a variable in the surrounding class is
accessed, when in fact a field from the super class is accessed. To make the intent of the code more clear it is recommended to add a
<b>this</b> qualifier to the field access call.
<p>Example:
<pre><code>
<b>class</b> X {
  <b>protected</b> String s;
}
<b>class</b> Y {
  <b>void</b> foo(String s) {
    <b>new</b> X() {{
      System.out.println(s); // here the field is accessed not the parameter
    }};
  }
}
</code></pre>
<!-- tooltip end -->
<p>
</body>
</html>