官术网_书友最值得收藏!

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) 
主站蜘蛛池模板: 乡城县| 社旗县| 耿马| 敦煌市| 博乐市| 类乌齐县| 定边县| 沾益县| 永丰县| 二连浩特市| 沙河市| 汉阴县| 嘉善县| 长春市| 宝兴县| 桦南县| 渝中区| 江门市| 九龙坡区| 巨鹿县| 光泽县| 刚察县| 绥滨县| 江油市| 连平县| 清镇市| 尼勒克县| 新和县| 瓮安县| 都兰县| 阳城县| 定襄县| 霍林郭勒市| 尼勒克县| 鄂托克旗| 鹤岗市| 共和县| 陆丰市| 洪江市| 老河口市| 梁山县|