Type system

Go type parameters

A type parameter stands for a type argument satisfying its constraint. Operations in a generic body must be allowed by the constraint. Instantiation substitutes type arguments. Example output: 'a'.

Formal Syntax & Structure

go syntaxgo
[T Constraint]

Working Example

Example Snippetgo
package main
import (  "fmt")
func first[T any](items []T) T { return items[0] }func main() {  fmt.Println(first([]string{"a", "b"}))}
Go Reference