Standard library / reflect
reflect.MakeMap()
Creates an initialized map of the given map type. Expected stdout: '1\n'.
Formal Syntax & Structure
go syntaxgo
func MakeMap(typ Type) ValueParameters & Attributes
| Name | Type | Description |
|---|---|---|
| typ | Type | Runtime type descriptor for the new value. |
Return Value
Value
Creates an initialized map of the given map type.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { m := reflect.MakeMap(reflect.TypeFor[map[string]int]()) m.SetMapIndex(reflect.ValueOf("a"), reflect.ValueOf(7)) fmt.Println(m.Len())}