コードで説明 func Min[T int | float64](a, b T) T { if a < b { return a } return b } func main() { fmt.Println(Min[int](5, 2)) fmt.Println(Min[float64](3.1, 9.7)) } https://go.dev/play/p/uCZq2OnksPK 型パラメータ 型引数
より詳しくGenerics沼に落ちたいかたはこちら ● Tutorial: Getting started with generics ○ https://go.dev/doc/tutorial/generics ● go generics for the busy gophers ○ https://sethops1.net/post/go-generics-for-the-busy-gopher/ ● Go 言語にやってくる Generics は我々に何をもたらすのか ○ https://zenn.dev/mattn/books/4c7de85ec42cb44cf285 ● Go 1.18集中連載 ジェネリクス ○ https://future-architect.github.io/articles/20220209a/