builtin.go文件中compare的定义是不是错误?

问题描述 投票:0回答:2

定义为:

//comparable is an interface that is implemented by all comparable types
// (booleans, numbers, strings, pointers, channels, arrays of comparable types,
// structs whose fields are all comparable types).
// The comparable interface may only be used as a type parameter constraint,
// not as the type of a variable.  

 type comparable interface{ comparable }

定义是什么意思?这不是一个递归接口吗?

go
2个回答
0
投票

builtin
包用于文档目的。它并不是真正进口的。根据包文档:

Packagebuiltin 提供了 Go 预声明标识符的文档。这里记录的项目实际上并不在内置包中,但它们在这里的描述允许 godoc 提供该语言的特殊标识符的文档。


0
投票

内置包文档说:

Packagebuiltin 提供了 Go 预声明标识符的文档。这里记录的项目实际上并不在内置包中,但它们在这里的描述允许 godoc 提供该语言的特殊标识符的文档。

类型声明

type comparable interface{ comparable }
实际上并不在包中。它只是一个用于附加文档的占位符。

© www.soinside.com 2019 - 2024. All rights reserved.