Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 479 Bytes

Type.Key.md

File metadata and controls

28 lines (19 loc) · 479 Bytes

Key() Type

参数列表

返回值:

  • Type reflect.Type 返回 map 类型 key 的类型。

功能说明:

  • reflect.TypeOf(interface{}).Key() 返回 map 类型 key 的类型。如果出现恐慌(panic),表示变量类型不是Map。

代码实例:

package main
import (
    "fmt"
    "reflect"
)

func main(){
	var a map[int]string
	var typeA reflect.Type = reflect.TypeOf(a)
	fmt.Println(typeA.Key(), typeA.Elem().Kind())
	//>>int string
}