do not mutate numberOfStudents counter

This commit is contained in:
gushakov
2022-01-04 17:53:56 +01:00
parent ff9f122f45
commit 8e29ebd7ef

View File

@@ -34,7 +34,8 @@ public class Course {
}
public Course enrollStudent() {
return newCourse().numberOfStudents(numberOfStudents.incrementAndGet()).build();
// notice that we are not mutating the instance counter here
return newCourse().numberOfStudents(numberOfStudents.get() + 1).build();
}
private CourseBuilder newCourse() {