新版本的变更 / Kotlin 1.5

// *** in version 1.5: ***
// the class compiles into a java.lang.Record, requires JVM target 16 or newer

@JvmRecord
data class User(val name: Stringval age: Int)

// Java sees the accessors name() and age(), plus equals(), hashCode()
// and toString() generated by the JVM itself

fun main() {
    val u = User("Ann"30)
    println(u)                 // User(name=Ann, age=30)
    println(u.copy(age = 31))  // the Kotlin data class API stays in place
}