美文网首页
kotlin 构造方法

kotlin 构造方法

作者: e56e2551219d | 来源:发表于2020-08-04 16:34 被阅读0次

     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

    }

    }

    相关文章

      网友评论

          本文标题:kotlin 构造方法

          本文链接:https://www.haomeiwen.com/subject/ppbsrktx.html