Java Lock variable assignment before use. Why?

前端 未结 5 1673
迷失自我
迷失自我 2020-12-06 07:11

In a lot of of the Java source, (for example LinkedBlockingDeque) I see things like this;

final ReentrantLock lock = new ReentrantLock();

publi         


        
5条回答
  •  没有蜡笔的小新
    2020-12-06 08:05

    When you assign to local variable in method, compiler can do some optimizations. see In ArrayBlockingQueue, why copy final member field into local final variable?

提交回复
热议问题