Kirill Grouchnikov
11/23/2020, 10:35 PMCollections.unmodifiableList
?CLOVIS
11/24/2020, 6:35 AMCLOVIS
11/24/2020, 6:39 AMCollections.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.