Suppose I have a SnapshotStateList for Student, and the definition of Student is:
data class Student<val id: Int, var name: String>
val students = mutableStateListOf(Student(0, "Aaron"))
My Jetpack compose in wants to recompose when students changes.
Found the following function to trigger it:
fun addStudent(name: String) {
students.add(Student(students.size, "Bob"))
}
fun removeStudent(key: Int) {
students.remove(key)
}
fun replaceStudent(key: Int, name: String) {
val old = students[key]
students[key] = Student(old.key, name)
}
But the following function cannot trigger it:
fun modifyStudent(key: Int, name: String) {
students[key].name = name
}
Why, how does SnapshotStateList detect that a change has occurred?