I use lombok library in my java project.
@Data
public class Score {
private long grade;
}
With this code, I have getter and setter automatically. e.g.
Score score = new Score();
score.setGrade(10);
// when I call score.getGrade(), I get 10.
But now I want to customize the setter method to introduce additional logics for the grade value. e.g.
public void setGrade(long grade) {
// so the returned value from getter is always 1 bigger than what has been set.
this.grade += 1;
}
Basically, I want to have score.setGrade(10)
but score.getGrade()
returns 11. That's override the setter.
How to achieve it with lombok in use?