reflect.MakeMap() Function in Golang with Examples Last Updated : 03 May, 2020 Comments Improve Suggest changes 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.MakeMap() Function in Golang is used to create a new map with the specified type. To access this function, one needs to imports the reflect package in the program. Syntax: func MakeMap(typ Type) Value Parameters: This function takes the following parameters: typ : This parameter is the Type. Return Value: This function returns a newly created map. Below examples illustrate the use of above method in Golang: Example 1: C // Golang program to illustrate // reflect.MakeMap() Function package main import ( "fmt" "reflect" ) // Main function func main() { var str map[int]string var strValue reflect.Value = reflect.ValueOf(&str) indirectStr := reflect.Indirect(strValue) //Use of MakeMap() method valueMap := reflect.MakeMap(indirectStr.Type()) fmt.Printf("ValueMap is [%v] .", valueMap) } Output: ValueMap is [map[]] . Example 2: C // Golang program to illustrate // reflect.MakeMap() Function package main import ( "fmt" "reflect" ) // Main function func main() { intSlice := make([]int, 0) mapStringInt := make(map[string]int) sliceType := reflect.TypeOf(intSlice) mapType := reflect.TypeOf(mapStringInt) intSliceReflect := reflect.MakeSlice(sliceType, 0, 0) mapReflect := reflect.MakeMap(mapType) v := 100 rv := reflect.ValueOf(v) intSliceReflect = reflect.Append(intSliceReflect, rv) intSlice2 := intSliceReflect.Interface().([]int) fmt.Println(intSlice2) k := "GeeksforGeeks" rk := reflect.ValueOf(k) mapReflect.SetMapIndex(rk, rv) mapStringInt2 := mapReflect.Interface().(map[string]int) fmt.Println(mapStringInt2) } Output: [100] map[GeeksforGeeks:100] Comment More infoAdvertise with us Next Article reflect.MakeMap() Function in Golang with Examples S SHUBHAMSINGH10 Follow Improve Article Tags : Go Language Write From Home Golang-reflect Similar Reads reflect.MakeChan() 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.MakeChan() Function in Golang is used to create a new channel with the specified type and buffer size. To access 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.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 represent 1 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.MakeMapWithSize() 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.MakeMapWithSize() Function in Golang is used to create a new map with the specified type and initial space for app 2 min read Like