- 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)
推薦閱讀
- Kali Linux Web Penetration Testing Cookbook
- C程序設計簡明教程(第二版)
- Apache Spark 2 for Beginners
- VMware vSphere 6.7虛擬化架構實戰指南
- Designing Hyper-V Solutions
- 學Python也可以這么有趣
- Java EE 7 Performance Tuning and Optimization
- Java編程的邏輯
- Mastering Git
- UNIX Linux程序設計教程
- Python 3.7從入門到精通(視頻教學版)
- INSTANT Silverlight 5 Animation
- Spring Boot+MVC實戰指南
- App Inventor少兒趣味編程動手做
- Python數據可視化之matplotlib實踐