There are many discussion about final local variables in Java. I looked into some Java's own source code, eg. DelayQueue, and saw code like below,
public class Foo {
private final transient ReentrantLock lock = ...
...
public void methodBar() {
final ReentrantLock lock = this.lock; // <=== HERE
lock.lock();
...
}
}
Questions:
- Any other reasons HERE having a local final var reference to the member var that's already final, except compiler optimization (CO) or to be used in anonymous inner classes? In the Java's source, certainly no inner classes used.
- How much runtime gain with CO in this case?