type-parameters

command module
v0.0.0-...-838b099 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2023 License: MIT Imports: 1 Imported by: 0

README

Type Parameters

Type Parameters in Functions

A Go function can be declared as follows:

func FunctionName(arg1 Type, arg2 Type, ...) {}

With Go generics, type parameters can now be applied to function declaration. Type parameters needs to be encapsulated in the square brackets [...] and before the function parameters.

func FunctionName[T1 TypeConstraint, T2 TypeContraint, ...](arg1 T, arg2 T,...) {}

Type Parameters in Types

With go 1.19, types can now be declared with type parameters.

type StructName[T TypeConstraint, ...] struct {
	attribute1 T
}

Reference

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL