- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 177字
- 2021-07-23 19:06:01
How it works...
Thanks to treating OnClickListener as a function, we were able to implement it in the clean and concise form of a lambda expression. The lambda's body will globally be invoked whenever the user clicks the button. In our case, once the button is clicked, it will be hidden away.
Lambda expressions are one of the most essential functional features of the language and are used extensively in the standard library components. They can be seen as an abbreviated form of a function or a functional interface implementation. Lambdas help to organize code correctly and reduce a lot of boilerplate code. The syntax of a lambda expression can be seen as a block of code placed between { } symbols. Lambda expressions can have function arguments defined explicitly, for example:
val myFunction: (View) -> Unit = { view ->
view.visibility = View.INVISIBLE
}
For the sake of brevity, the explicit parameter can be omitted. However, we can still access it using it modifier:
val myFunction: (View) -> Unit = {
it.visibility = View.INVISIBLE
}
- Mastering Visual Studio 2017
- Git Version Control Cookbook
- ADI DSP應用技術集錦
- Unreal Engine 4 Shaders and Effects Cookbook
- 單片機C語言程序設計實訓100例
- Python機器學習算法: 原理、實現與案例
- 零基礎Java學習筆記
- C++反匯編與逆向分析技術揭秘(第2版)
- TMS320LF240x芯片原理、設計及應用
- Building UIs with Wijmo
- 輕松學Scratch 3.0 少兒編程(全彩)
- 零基礎入門Python數據分析與機器學習
- 深度剖析ApacheDubbo核心技術內幕
- Instant AutoIt Scripting
- Spring Boot實戰:從0開始動手搭建企業級項目