What do you think of this ImmutableList class defi...
# random
g
What do you think of this ImmutableList class definition?
Copy code
class ImmutableList<T>(list: List<T>) : List<T> by list.toList()
đŸ‘€ 1
l
I don't think it's a given that
toList
will return you a new list
So maybe it's not immutable?
l
toList
will give you a new
ArrayList
c
g
@LeoColman good point, it depends on the implementation of
toList
. What about declaring it as:
Copy code
class ImmutableList<T>(list: List<T>) : List<T> by ArrayList(list)
we miss the empty list and singletonlist optimizations from inside
toList
but that’s probably alright