Use primitive arrays in place of Array<T>

Honestly, I think we really talk about the same thing here :smiley: I mean a very similar class to yours, but just implementing List/MutableList instead of ArrayWrapper. I don’t see benefits of ArrayWrapper and benefits of implementing a list are pretty obvious.

List is read only
MutableList has to, by spec, be able to grow in size.
An array fits neither of their descriptions.

It doesn’t. Methods that would change the size can instead throw UnsupportedOperationException. That’s exactly what that exception was intended for; and it’s what e.g. Java’s Arrays.asList() does.

Of course, a MutableList isn’t a perfect match for a wrapped array. But it could still work.

2 Likes