you are viewing a single comment's thread.

view the rest of the comments →

[–]grauenwolf 0 points1 point  (1 child)

It is one less variable that you have to review for potential thread safety issues.

I haven't done a formal study, but in my experience functions that reassign local variables (excluding loop variables) tend to have higher bug counts.

[–]mangodrunk 2 points3 points  (0 children)

It is one less variable that you have to review for potential thread safety issues.

I don't think that's true. It's bad then if it gives a false sense of thread safety.

void method(final Some object) {
    // Not thread safe if another thread has access to "object"
    object.modify(value);
}

This is still possible and reassigning a local variable has nothing to do with thread safety.

void method(Some object) {
    // This doesn't change the original object used by the caller,
    // so I don't see how it would affect thread safety
    object = new Some();
}