Back to all rules
What this rule checks
A user-defined class is instantiated more than once (a new inside a loop counts as several; an array allocation such as new Ball[3] does not)
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;
  Ball(float startX) { x = startX; }
  void show() { ellipse(x, 200, 20, 20); }
}
Ball left = new Ball(100);
Ball right = new Ball(300);

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

void draw() {
  left.show();
  right.show();
}
FAIL — this code triggers the rule
class Ball {
  float x;
  Ball(float startX) { x = startX; }
  void show() { ellipse(x, 200, 20, 20); }
}
Ball only = new Ball(100);  // just one object

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

void draw() {
  only.show();
}
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.MultipleInstantiationRule
Message template No user-defined class is instantiated more than once.