- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 160字
- 2021-07-23 19:05:57
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.
- Rust編程:入門、實(shí)戰(zhàn)與進(jìn)階
- Ceph Cookbook
- C#編程入門指南(上下冊)
- Python爬蟲開發(fā)與項(xiàng)目實(shí)戰(zhàn)
- Django:Web Development with Python
- ANSYS Fluent 二次開發(fā)指南
- Java網(wǎng)絡(luò)編程核心技術(shù)詳解(視頻微課版)
- 深度學(xué)習(xí):Java語言實(shí)現(xiàn)
- 持續(xù)輕量級Java EE開發(fā):編寫可測試的代碼
- Procedural Content Generation for C++ Game Development
- 計(jì)算機(jī)程序的構(gòu)造和解釋(JavaScript版)
- Koa與Node.js開發(fā)實(shí)戰(zhàn)
- Hands-On Data Visualization with Bokeh
- 精通Rust(第2版)
- Computer Vision with Python 3