Is there a Kotlin "idiomatic" one-liner counterpar...
# announcements
k
Is there a Kotlin "idiomatic" one-liner counterpart of Java's
Collections.unmodifiableList
?
c
What you want is probably available in kotlinx.immutable
Other than that,
Collections.unmodifiableList()
gives a read-only list, not immutable. To get an easy thin read-only wrapper, you can write:
data class ReadOnlyList<T>(private val list: List<T>) : List<T> by list
fun <T> List<T>.asReadOnly() = ReadOnlyList(this)
I wish it was added to the standard library, but at least that's only 2 lines of code so it's really not a big deal.