Sobes.tech
Junior — Middle

Milline sisseehitatud funktsioon on kasutusel Map objekti tüübi määramiseks programmeerimiskeeles?

sobes.tech AI

Vastus AI-lt

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.