Ars
Ars

Reputation: 639

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

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?

Upvotes: 3

Views: 435

Answers (1)

curiouscupcake
curiouscupcake

Reputation: 1277

Try Lombok: https://projectlombok.org/setup/maven, a simple annotation @Data

for your class definition will remove your code boilerplate (getter/setter/constructor/etc.).

Upvotes: 1

Related Questions