对象的复制和数据类成员的解构

copy()该函数的作用就是复制数据类的实例

package loaderman

import loaderman.demo.User


fun main(arg: Array<String>) {

    val user1 = User("haha")
    val user2 = User("haha")
    val copy = user1.copy(name = "heihei")

    println(user1)
    println(user2)
    println(copy)
    println(user1.equals(user2))

}
package loaderman

import loaderman.demo.User


fun main(arg: Array<String>) {

    val user1 = User("haha")
    val (name) = User("haha")//数据类解构
    val copy = user1.copy(name = "heihei")

    println(user1)
    println(name)
    println(copy)

}

 

posted on 2018-12-17 22:00  LoaderMan  阅读(260)  评论(0编辑  收藏  举报

导航