Search code examples
javapmd

pmd rule overridable method called during object construction


I am initializing some member variables in my DTO via setters from inside the constructor.

But the below pmd error showing so how to eliminate that pmd rule violation?

Overridden method 'setAbc' called during object construction

class A{

private String x;

public getX(){
return x;
}
public setX(String x){
this.x = x ;
}
A(){}

A(B b){
setX("C");
}

}


Solution

  • How about making method setX final? Or perhaps event the entire class?