Answer the question
In order to leave comments, you need to log in
Why is using synchronized in setter bad?
This question came up in an interview.
Answer the question
In order to leave comments, you need to log in
Perhaps because the setter must be used to set the value of a single field, and using synchronized for this is redundant.
Because it usually doesn't make any sense.
Unless you take into account something like
void setVar(int var) {
if(var == null) {
this.var = var;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question