How do you implement a container for different types in Go? [duplicate]
问题 This question already has answers here : What would generics in Go be? (2 answers) Closed 2 years ago . The following code implements a List of ints in Go: package main import "fmt" type List struct { Head int Tail *List } func tail(list List) *List { return list.Tail } func main() { list := List{Head: 1, Tail: &List{Head: 2, Tail: &List{Head: 3, Tail: nil}}} fmt.Println(tail(list).Head) } Problem is this only works for int . If I wanted a list of strings , I'd need to re-implement every list