<@U66SV6HSQ> you could create your own List-Type a...
# announcements
a
@nickk you could create your own List-Type and use delegation
Copy code
class MyImmutableList<T>(private val list: List<T>): List<T> by list
then the user won't be able to cast your list into a
MutableList
and therefore won't be able to edit it
a
isn't that just a reinvention of Collections.unmodifiableList ?
(which would also do things like protecting against calling remove() on the iterator, for example)
a
they are pretty similar, my example prohibits the cast to
MutableList<T>
,
Collections.unmodifiableList
just throws an exception when you call
add