reflect.MapOf() Function in Golang with Examples Last Updated : 28 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: Example 1: C // Golang program to illustrate // reflect.MapOf() Function package main import ( "fmt" "reflect" ) // Main function func main() { var i interface{} // use of MapOf method tm := reflect.MapOf(reflect.TypeOf("string"), reflect.TypeOf(&i).Elem()) fmt.Println(tm) } Output: map[string]interface {} Example 2: C // Golang program to illustrate // reflect.MapOf() Function package main import ( "fmt" "reflect" ) // Main function func main() { ta := reflect.ArrayOf(5, reflect.TypeOf(123)) tc := reflect.ChanOf(reflect.SendDir, ta) //use of MapOf method tm := reflect.MapOf(ta, tc) fmt.Println(tm) } Output: map[[5]int]chan<- [5]int Comment More infoAdvertise with us Next Article reflect.MapOf() Function in Golang with Examples S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Golang-reflect Similar Reads reflect.MakeMap() 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.MakeMap() Function in Golang is used to create a new map with the specified type. To access this function, one nee 2 min read reflect.MapKeys() 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.MapKeys() Function in Golang is used to get a slice containing all the keys present in the map, in unspecified or 2 min read reflect.MapIndex() 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.MapIndex() Function in Golang is used to get the value associated with key in the map v. To access this function, 2 min read reflect.MakeFunc() 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.MakeFunc() Function in Golang is used to get the new function of the given Type that wraps the function fn. To acc 2 min read reflect.PtrTo() 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.PtrTo() Function in Golang is used to get the pointer type with element t, i.e., t represents type Geek, PtrTo(t) 1 min read Like