Back to all rules
What this rule checks
A user-defined class declares an attribute with an initializer
Configuration
When off, this rule is excluded from pipeline runs. Changes apply immediately.
Code Examples
PASS — this code satisfies the rule
class Ball {
  float x = 0;
  float speed = 2;
  void move() { x = x + speed; }
}
Ball b = new Ball();

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

void draw() {
  b.move();
  ellipse(b.x, 200, 20, 20);
}
FAIL — this code triggers the rule
class Ball {
  float x, speed;  // no starting values here
  Ball() { x = 0; speed = 2; }
  void move() { x = x + speed; }
}
Ball b = new Ball();

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

void draw() {
  b.move();
  ellipse(b.x, 200, 20, 20);
}
Overview
Category Topic Classes
Level Intermediate
Type Custom Zita
Priority 3 (1 = highest, 5 = lowest)
Status Active
PMD Configuration
Java class nl.utwente.processing.pmd.rules.ClassAttrInitRule
Message template No class attribute is declared with an initializer.