Back to all rules
What this rule checks
No field named after the class it's in (e.g. a field score in class Score)
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
class Score {
  int points = 0;
  void show() { text(points, 20, 20); }
}
Score s = new Score();

void setup() {
  size(400, 400);
}

void draw() {
  s.show();
}
FAIL — this code triggers the rule
class Score {
  int score = 0;  // field has the same name as its class
  void show() { text(score, 20, 20); }
}
Score s = new Score();

void setup() {
  size(400, 400);
}

void draw() {
  s.show();
}
Overview
Category Topic Classes
Level Advanced
Type Built-in PMD
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
PMD reference category/java/errorprone.xml/AvoidFieldNameMatchingTypeName