- 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)
推薦閱讀
- Functional Python Programming
- 零基礎玩轉區塊鏈
- PyTorch Artificial Intelligence Fundamentals
- Responsive Web Design with HTML5 and CSS3
- Linux操作系統基礎案例教程
- Java編程技術與項目實戰(第2版)
- Mathematica Data Analysis
- Python算法從菜鳥到達人
- Java Web開發詳解
- Machine Learning in Java
- Java語言程序設計教程
- Lift Application Development Cookbook
- Practical Microservices
- C語言程序設計
- C語言程序設計