- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 108字
- 2021-06-24 14:13:28
Instantiating classes
Creating an instance of a class will be familiar to readers who have experience of object-orientated programming. The syntax in many languages uses a new keyword followed by the name of the class to be created. The new keyword indicates to the compiler that the special constructor function should be invoked to initialize the new instance.
Kotlin, however, removes this ceremony. It treats calling a constructor function the same as a normal function, with the constructor function using the name of the class. This enables Kotlin to drop the new keyword entirely. Arguments are passed in as normal:
val file = File("/etc/nginx/nginx.conf") val date = BigDecimal(100)
推薦閱讀
- HTML5移動Web開發技術
- Apache Oozie Essentials
- arc42 by Example
- Reactive Programming with Swift
- 從程序員到架構師:大數據量、緩存、高并發、微服務、多團隊協同等核心場景實戰
- Python數據可視化之Matplotlib與Pyecharts實戰
- 快速念咒:MySQL入門指南與進階實戰
- 深入理解Android:Wi-Fi、NFC和GPS卷
- 基于SpringBoot實現:Java分布式中間件開發入門與實戰
- Learning Concurrency in Python
- LabVIEW數據采集
- Web開發的平民英雄:PHP+MySQL
- Kohana 3.0 Beginner's Guide
- 秒懂算法:用常識解讀數據結構與算法
- TensorFlow 2.0深度學習應用實踐