Standard library / reflect
reflect.MapOf()
Construct a map type. The key type must be comparable; this operation does not allocate a map. Expected stdout: 'map[string]int\n'.
Formal Syntax & Structure
go syntaxgo
func MapOf(key, elem Type) TypeParameters & Attributes
| Name | Type | Description |
|---|---|---|
| key | Type | Comparable key type; an invalid key type panics. |
| elem | Type | Element type of the resulting collection. |
Return Value
Type
Construct a map type.
Working Example
Example Snippetgo
package main
import ( "fmt" "reflect")
func main() { fmt.Println(reflect.MapOf(reflect.TypeOf(""), reflect.TypeOf(0))) }