CopyOnWriteArrayList
methods that mutate its state (add
, set
, etc) acquire the lock following way:
final ReentrantLock lock = this.lock;
lock.lock();
Why does it save this.lock
into a local variable? this.lock
is declared final so it can't change anyway. Why couldn't we just write this.lock.lock()
? Does it have some implication on concurrency or is it just a matter of taste?
Here is the link to source code.