gpt4 book ai didi

go2go.playground - 预期类型,发现 'type'(还有 1 个错误)

转载 作者:行者123 更新时间:2023-12-02 11:24:36 25 4
gpt4 key购买 nike

我尝试运行来自 design draft 的示例( The Next Step for Generics ) 在
go2go.playground

type Pair(type T) struct { f1, f2 T }
,但得到一个错误
prog.go2:14:11: expected type, found 'type' (and 1 more errors)
我在哪里可以找到实际的 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 }
但:
type Pair[T any] struct { f1, f2 T }

关于go2go.playground - 预期类型,发现 'type'(还有 1 个错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64152852/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com