What's the benefit of creating a final local reference to a member variable that's already final?

Viewed 29

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:

  1. 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.
  2. How much runtime gain with CO in this case?
0 Answers
Related