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

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) 
主站蜘蛛池模板: 门头沟区| 鹿泉市| 平顶山市| 霍林郭勒市| 白城市| 贵港市| 涿州市| 绥滨县| 盐源县| 姚安县| 锡林浩特市| 平顶山市| 屏边| 望奎县| 佛山市| 曲松县| 宽城| 平乡县| 霸州市| 历史| 清苑县| 三原县| 资中县| 阳朔县| 永康市| 丰县| 南阳市| 定陶县| 绩溪县| 辽阳县| 黄龙县| 东阿县| 神池县| 灵山县| 蚌埠市| 玛多县| 安丘市| 义乌市| 凤山市| 兴安县| 海兴县|