Hi fellow generic experts
I'd like to ask why does the last line in the below Snippet 1 fails with
the error:
./prog.go:17:26: in call to slices.Index, S (type []interface{}) does not
satisfy ~[]E
The third line is essentially the same line, but it works!
Snippet 1: Full code in https://go.dev/play/p/PPdIaK08v5A
```
func main() {
mySlice := []interface{}{1, "a", MyStruct{A: 2, B: 3}}
fmt.Println(slices.Index(mySlice, 1))
fmt.Println(slices.Index(mySlice, "a"))
fmt.Println(slices.Index(mySlice, interface{}(MyStruct{A: 2, B: 3})))
// Below does not work.
// fmt.Println(slices.Index(mySlice, MyStruct{A: 2, B: 3}))
}
```
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/67f5a2c2-636e-43c3-81be-c2ec9098f884n%40googlegroups.com.