-
-
Save einsitang/2ec35b927f267843ff45cd3257c8da97 to your computer and use it in GitHub Desktop.
go 泛型歧义
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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