Do you just want to change the item at position 0 in the list?
list[0] = User("Peter", "15:15")
If you want to replace the item with one that's a copy, but with certain changes:
list[0] = list[0].copy(name="Peter")
If you want to keep the same object at position 0, but change its state:
// note the use of var, so the properties are mutable
data class User(var name: String, var date: String)
// "get item 0, if it's not null, set these things on it",
// this is just a neat and concise way to do it
list[0]?.run {
name = "Peter"
date = "15:15"
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…