kotlin 构造方法

2020-08-04  本文已影响0人  e56e2551219d

 Kotlin的构造函数分为主构造器(primary constructor)和次级构造器(secondary constructor)。

/**

* 主构造

*/

class ItemInfo constructor(name: String, id: Int) {

var name: String =""

    var id: Int =0

    init {

this.name = name

this.id = id

}

/**

    * 次构造

    */

    constructor(id :Int) :this("",id){

this.id = id

}

}

上一篇下一篇

猜你喜欢

热点阅读