ursus
05/17/2026, 9:42 PMinterface Store {
val users: List<String>
}
class StoreImpl : Store {
private val mutableUsers = mutableListOf<String>()
override val users: List<String>
get() = mutableUsers
fun addUser(name: String) {
mutableUsers += name
}
}
can I use explicit backing fields here somehow? i.e. when the property is defined on the interfaceYoussef Shoaib [MOD]
05/17/2026, 10:11 PMclass StoreImpl : Store {
override val users: List<String>
field = mutableListOf()
fun addUser(name: String) {
users += name
}
}Youssef Shoaib [MOD]
05/17/2026, 10:11 PMursus
05/17/2026, 10:47 PMephemient
05/19/2026, 4:38 PMfinal override val users: List<String>Youssef Shoaib [MOD]
05/19/2026, 4:46 PMfinalloke
05/20/2026, 1:58 PMaddUser ? I.e. it won't actually mutate the list because the exposed type is just List .Youssef Shoaib [MOD]
05/20/2026, 1:59 PMMutableList.plusAssign specifically calls .add. you can also call .add yourselfloke
05/20/2026, 3:50 PMusers is declared as List, not MutableList.ursus
05/20/2026, 3:51 PMYoussef Shoaib [MOD]
05/20/2026, 3:51 PMval, so += wouldn't work!
The whole point is we're using the new explicit backing field feature, which lets you access the real type of the field inside the class, but hide it from the outsideursus
05/21/2026, 4:23 PMfinal getting grayed out is IDE being old? (latest AS)