标签: go
这有效:
type T string var t T = "hello"
http://play.golang.org/p/275jQ4ixvp
但是cannot use s (type string) as type T in assignment
cannot use s (type string) as type T in assignment
type T string s := "world" var t T = s
http://play.golang.org/p/vm3mC5ltcE
如何让第二种情况发挥作用?
答案 0 :(得分:4)
将字符串转换为正确的类型[conversions]
http://play.golang.org/p/dkavI_QgPb
s := "world" t := T(s) fmt.Println(t)