What’s the best way to do something among the line...
# announcements
z
What’s the best way to do something among the lines of
Copy code
class Foo {
    val bar = mutableListOf<Bar>()
        get() {
            return listOf(*bar.toTypedArray())
        }
}
? It would seem that the only way is to really just do
Copy code
val bar = mutableListOf<Bar>()
...
fun getBar(): List<Bar> = bar
, but the result is that it you get two getters with the same signature on the JVM Update: If you just add the
@JvmField
decorator, you don’t have to deal with that, but is there a way to do it as closely to the top idea? Because you can still just get the mutableList as a property apparently Update: Backing the field is probably the solution.
j
Yeah a private backing field is probably what you're wanting