Skip to content

Instantly share code, notes, and snippets.

@einsitang
Last active June 5, 2023 13:53
Show Gist options
  • Save einsitang/2ec35b927f267843ff45cd3257c8da97 to your computer and use it in GitHub Desktop.
Save einsitang/2ec35b927f267843ff45cd3257c8da97 to your computer and use it in GitHub Desktop.
go 泛型歧义
package test
type Handler func(str string) string
type FuncMap map[string]Handler
func aDo() {
p := "message"
S := "key"
Fn := make(FuncMap)
// 这里的[]是取下标
Fn[S](p)
}
package test
type S string
func Fn[T S](str T) T {
return str
}
func bDo() {
var p S
// 这里的[S]是声明泛型类型
Fn[S](p)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment