koz*_*zmo 3 generics go go-playground go-2
我尝试从设计草案(泛型的下一步)中 运行示例go2go.playground
type Pair(type T) struct { f1, f2 T }
Run Code Online (Sandbox Code Playgroud)
,但得到一个错误
prog.go2:14:11: expected type, found 'type' (and 1 more errors)
Run Code Online (Sandbox Code Playgroud)
我在哪里可以找到实际的go generics design draft?
您正在查看过时的设计草案。
这是最新的:https : //go.googlesource.com/proposal/+/refs/heads/master/design/go2draft-type-parameters.md
所以,它不是:
type Pair(type T) struct { f1, f2 T }
Run Code Online (Sandbox Code Playgroud)
但:
type Pair[T any] struct { f1, f2 T }
Run Code Online (Sandbox Code Playgroud)