官术网_书友最值得收藏!

How it works...

The performHavingLock() function allows us to provide synchronization for the function passed to it as the task parameter:

performHavingLock(ReentrantLock()) {
print("Wait for it!")
}

As a result, the performHavingLock() function is going to print the following output to the console:

Wait for it!

Under the hood, the inline modifier affects both the function itself and the lambda expressions passed to it. They are all going to be inlined in the underlying generated bytecode:

Lock lock = (Lock)(new ReentrantLock());
lock.lock();

try {
String var2 = "Wait for it!";
System.out.print(var2);
} finally {
lock.unlock();
}

If we did not use the inline modifier, the compiler would create a separate instance of the Function0 type in order to pass the lambda argument to the performHavingLock() function. Inlining lambdas may cause the generated code to grow. However, if we do it in a reasonable way (that is, avoiding inlining large functions), it will pay off in performance. 

主站蜘蛛池模板: 嫩江县| 开鲁县| 遂川县| 岱山县| 平利县| 莱西市| 延安市| 永清县| 涟水县| 塔城市| 青河县| 永善县| 甘德县| 莱阳市| 株洲市| 莱芜市| 广水市| 阳西县| 丹江口市| 商城县| 漠河县| 全椒县| 定兴县| 沽源县| 沐川县| 广丰县| 万州区| 和田县| 鲜城| 青铜峡市| 湄潭县| 嘉定区| 务川| 宜阳县| 灵寿县| 长葛市| 启东市| 永平县| 土默特左旗| 安西县| 泉州市|