若一个类型指定了[类型参数],则此类型成为泛型类型。

type List[T any] struct {
	next  *List[T]
	value T
}

类型参数

类型参数的语法如下:

TypeParameters  = "[" TypeParamList [ "," ] "]" .
TypeParamList   = TypeParamDecl { "," TypeParamDecl } .
TypeParamDecl   = IdentifierList TypeConstraint .

其中 TypeConstraint 即为:

TypeConstraint
TypeElem       = TypeTerm { "|" TypeTerm } .
TypeTerm       = Type | UnderlyingType .
UnderlyingType = "~" Type .
Last moify: 2022-12-04 15:11:33
Build time:2025-07-18 09:41:42
Powered By asphinx