- Kotlin Blueprints
- Ashish Belagali Hardik Trivedi Akshay Chordiya
- 203字
- 2021-07-02 21:50:09
Concise yet expressive code
While being interoperable, Kotlin code is far superior to Java code. Like Scala, Kotlin uses type inference to cut down on a lot of boilerplate code and makes it concise. (Type inference is a better feature than dynamic typing as it reduces the code without sacrificing the robustness of the end product). However, unlike Scala, Kotlin code is easy to read and understand, even for someone who may not know Kotlin.
Kotlin's data class construct is the most prominent example of being concise as shown in the following:
data class Employee (val id: Long, var name: String)
Compared to its Java counterpart, the preceding line has packed into it the class definition, member variables, constructor, getter-setter methods, and also the utility methods, such as equals() and hashCode(). This will easily take 15-20 lines of Java code.
The data classes construct is not an isolated example. There are many others where the syntax is concise and expressive. Consider the following as additional examples:
- Kotlin's default values to function parameters save the need to overload the functions
- Kotlin's extension functions can be used to add domain-specific functionality to existing classes, making it easy for someone from the domain to understand
- INSTANT OpenCV Starter
- 三維圖形化C++趣味編程
- Unity 2D Game Development Cookbook
- NGINX Cookbook
- Ext JS 4 Plugin and Extension Development
- 從零開始學(xué)UI設(shè)計(jì)·基礎(chǔ)篇
- Analytics for the Internet of Things(IoT)
- Java EE應(yīng)用開發(fā)及實(shí)訓(xùn)
- Learning Yeoman
- 接口自動(dòng)化測(cè)試持續(xù)集成:Postman+Newman+Git+Jenkins+釘釘
- LabVIEW案例實(shí)戰(zhàn)
- Elixir Cookbook
- Advanced Analytics with R and Tableau
- 思維黑客:讓大腦重裝升級(jí)的75個(gè)超頻用腦法
- 云原生基礎(chǔ)架構(gòu):構(gòu)建和管理現(xiàn)代可擴(kuò)展基礎(chǔ)架構(gòu)的模式及實(shí)踐