What is the output?
data class User(
val name: String,
val points: Int
)
fun main() {
val a = User("Ana", 3)
val b = a.copy(points = 8)
print(a.points)
print(", ")
println(b.points)
}
Try it in the online Kotlin Playground →
[spoiler title="Solution"]
Answer:
3, 8
Explanation:
copy creates a new object. a stays unchanged while b has updated points.
[/spoiler]