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

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) 
主站蜘蛛池模板: 同江市| 商都县| 甘德县| 阳春市| 马关县| 漠河县| 鹰潭市| 小金县| 海伦市| 长岛县| 龙口市| 含山县| 抚远县| 武义县| 曲沃县| 白玉县| 玉门市| 临桂县| 大名县| 临桂县| 谢通门县| 和平县| 西吉县| 苏州市| 南靖县| 阜平县| 贡山| 定日县| 山东| 儋州市| 大邑县| 漯河市| 台湾省| 晋宁县| 绥宁县| 定边县| 涞水县| 象州县| 神池县| 乳山市| 老河口市|