The thing you are missing is that T
and interface{}
which holds a value of T
have different representations in memory so can't be trivially converted.
A variable of type T
is just its value in memory. There is no associated type information (in Go every variable has a single type known at compile time not at run time). It is represented in memory like this:
An interface{}
holding a variable of type T
is represented in memory like this
T
So coming back to your original question: why go does't implicitly convert []T
to []interface{}
?
Converting []T
to []interface{}
would involve creating a new slice of interface {}
values which is a non-trivial operation since the in-memory layout is completely different.