Standard library / go/types

go/types.NewMap()

Constructs a map type descriptor. This does not allocate a runtime value. Expected stdout: 'map[string]int\n'.

Formal Syntax & Structure

go syntaxgo
func NewMap(key, elem Type) *Map

Parameters & Attributes

NameTypeDescription
keyTypeMap key type.
elemTypeElement type.

Return Value

*Map

Constructs a map type descriptor.

Working Example

Example Snippetgo
package main
import (  "fmt"  "go/types")
func main() { fmt.Println(types.NewMap(types.Typ[types.String], types.Typ[types.Int])) }
Go Reference