Back to all rules
What this rule checks
Uses a generic type argument (e.g. List<Integer>)
Code Examples
PASS — this code satisfies the rule
Ball[] balls = new Ball[3]; // an array of Ball, no type argument
void setup() {
size(400, 400);
for (int i = 0; i < balls.length; i++) {
balls[i] = new Ball(100 + i * 100);
}
}
void draw() {
background(255);
for (int i = 0; i < balls.length; i++) {
balls[i].show();
}
}
class Ball {
float x;
Ball(float startX) {
x = startX;
}
void show() {
ellipse(x, 200, 30, 30);
}
}
FAIL — this code triggers the rule
ArrayList<Ball> balls = new ArrayList<Ball>(); // <Ball> is a type argument
void setup() {
size(400, 400);
for (int i = 0; i < 3; i++) {
balls.add(new Ball(100 + i * 100));
}
}
void draw() {
background(255);
for (int i = 0; i < balls.size(); i++) {
balls.get(i).show();
}
}
class Ball {
float x;
Ball(float startX) {
x = startX;
}
void show() {
ellipse(x, 200, 30, 30);
}
}
Overview
| Category |
Out of Scope
|
| Type |
Custom Zita
|
| Priority |
3 (1 = highest, 5 = lowest) |
| Status |
Active
|
PMD Configuration
| Java class |
nl.utwente.processing.pmd.rules.HasGenericsRule |
| Message template |
Generic type argument used. |