This is my personal collection of daily lessons, professional insights, and programming experiences. It’s a space where I document what I learn, and you can explore and learn from my journey too.
Tuesday, September 13, 2022
Update particular item's value from a list of data class Kotlin
Your data class should have mutable properties so that they can be changed:
fun <T> updateWorkerData(id: Int, property: KMutableProperty1<Worker, T>, value: T) { val workers = getListOfWorker() workers.forEach { if (it.id == id) { property.set(it, value) } } } updateWorkerData(1, Worker::age, 28)
Subscribe to:
Comments (Atom)
