Why does sonar shows duplication error on a class with a constructor and a setter?

Viewed 221

For example:

class a {

int field1;
int field2;

public a(int field1, int field2){ this.field1 = field1; this.field2 = field2;}

void setField1(int field1) {this.field1 = field1;}
void setField2(int field2) {this.field2 = field2;}
}

Sometimes when i create an instance, i need to set both parameters, and sometimes i need to change some values, so i need both setters and constructor. Why does SONAR marks this as duplicate? Is there only option is to tell sonar not to scan enitity files or there is a better way to solve this?

1 Answers
Related