Sobes.tech
Junior — Middle

Which built-in function is applicable for determining the type of a Map object in programming language?

sobes.tech AI

Answer from AI

In Go, to determine the type of an object, including checking if a variable is of type map, the function reflect.TypeOf from the reflect package is used.

Example:

package main

import (
    "fmt"
    "reflect"
)

func main() {
    m := make(map[string]int)
    t := reflect.TypeOf(m)
    fmt.Println(t.Kind() == reflect.Map) // true
}

Here, t.Kind() returns the constant reflect.Map if the object is a map.