Search
Calendar
July 2017
S M T W T F S
« Sep    
 1
2345678
9101112131415
16171819202122
23242526272829
3031  
Your widget title
Archives

PostHeaderIcon Sonar / Constructor Calls Overridable Method

How to fix the Sonar’s following report?

Constructor Calls Overridable Method 

In the constructor of your class, assign the parameters to the right fields using the ‘=’ operator, and not the setXXX() methods. Indeed, the latter may be overriden by subclass.
Eg:
Replace:

public Constructor(Param param){
    setField(param);
}

With:

public Constructor(Param param){
    this.field = param;
}

Leave a Reply