func TypeAssertion(arg ...interface{}){
for _,v := range arg{
switch reflect.TypeOf(v).Kind() {
case reflect.String:
fmt.Printf("arg %v type of string\n",v)
case reflect.Int64:
fmt.Printf("arg %v type of Int64\n",v)
case reflect.Int32:
fmt.Printf("arg %v type of Int32\n",v)
case reflect.Int16:
fmt.Printf("arg %v type of Int16\n",v)
case reflect.Int8:
fmt.Printf("arg %v type of Int8\n",v)
case reflect.Int:
fmt.Printf("arg %v type of Int\n",v)
case reflect.Uint64:
fmt.Printf("arg %v type of Uint64\n",v)
case reflect.Uint32:
fmt.Printf("arg %v type of Uint32\n",v)
case reflect.Uint16:
fmt.Printf("arg %v type of Uint16\n",v)
case reflect.Uint8:
fmt.Printf("arg %v type of Uint8\n",v)
case reflect.Uint:
fmt.Printf("arg %v type of Uint\n",v)
case reflect.Bool:
fmt.Printf("arg %v type of Bool\n",v)
case reflect.Float64:
fmt.Printf("arg %v type of Float64\n",v)
case reflect.Float32:
fmt.Printf("arg %v type of Float64\n",v)
case reflect.Slice:
fmt.Printf("arg %v type of Slice\n",v)
case reflect.Map:
fmt.Printf("arg %v type of Map\n",v)
case reflect.Struct:
fmt.Printf("arg %v type of Struct\n",v)
case reflect.Chan:
fmt.Printf("arg %v type of Chan\n",v)
case reflect.Array:
fmt.Printf("arg %v type of Array\n",v)
case reflect.Func:
fmt.Printf("arg %v type of Func\n",v)
case reflect.Interface:
fmt.Printf("arg %v type of Interface\n",v)
case reflect.Complex64:
fmt.Printf("arg %v type of Complex64\n",v)
case reflect.Complex128:
fmt.Printf("arg %v type of Complex128\n",v)
case reflect.UnsafePointer:
fmt.Printf("arg %v type of UnsafePointer\n",v)
default:
fmt.Printf("arg %v type of Unknow\n",v)
}
}
}
Go类型断言
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...