Avatar ·

Type conversion of interface slices in Go: why doesn't this work?

Hello everyone! I'm new to Go and can't figure out type conversion for interface slices. I have a function that takes `[]interface{}`, but I want to pass it a slice of a specific type, like `[]string`. Why doesn't Go allow this directly?\n\nHere's an example code that doesn't work:\n\n```go\npackage main\n\nimport "fmt"\n\nfunc printAll(items []interface{}) {\n for _, item := range items {\n fmt.Println(item)\n }\n}\n\nfunc main() {\n names := []string{"Alice", "Bob", "Charlie"}\n // Error: cannot use names (type []string) as type []interface{} in argument to printAll\n printAll(names)\n}\n```\n\nI understand that `string` implements the `interface{}` interface, but why can't `[]string` be used as `[]interface{}`? In the document