1 可以赋值各种类型
type Element interface{}
2 类型判断 comma - ok
var xx Element = 1
if _,ok:=xx.(int);ok{
fmt.Print("xdf")
}
3 类型判断 switch
type List []Element
//...
list := make(List,3)
list[0] =1
list[1]="hello"
list[2]=Person{"denis",70}
for index,ele :=range list {
switch value := ele.(type) {
case int:
//...
case string:
//...
case Person:
//...
default:
//...
}
}
ele.(type)
只能在switch只使用