reflect.MapOf() Function in Golang with Examples
Go language provides inbuilt support implementation of run-time reflection and allowing a program to manipulate objects with arbitrary types with the help of reflect package. The reflect.MapOf() Function in Golang is used to get the map type with the given key and element types, i.e., if k represents int and e represents string, MapOf(k, e) represents map[int]string. To access this function, one needs to imports the reflect package in the program.
Syntax:func MapOf(key, elem Type) Type
Parameters: This function takes three parameters of Type type(key, elem).
Return Value: This function returns the map type with the given key and element types.
Below examples illustrate the use of the above method in Golang: