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) }