3 ms·
I read that sentence, but it refers to a different problem. The author is trying to explain why you can't fix the problem by simply having the runtime automatic
by simiones 7y ago
I read that sentence, but it refers to a different problem. The author is trying to explain why you can't fix the problem by simply having the runtime automatically copy your []struct to a []interface (if it did so, any operation which was supposed to modify the original slice would instead modify the auto-created copy, which wouldn't be correct):
> It could allocate a new slice of interface values for you, and assign the concrete User values into corresponding indexes:
> [snipping example]
> Indeed, for getNames(users) this would actually work fine! But slices have mutable indexes. and many functions mutate the slices they're passed.
Again, this is not a real problem, and it could be pretty easily worked around. The real problem is that the slice type is neither covariant nor contravariant.