Type switch in golang

In the golang language, there is also a way of using javascript.

like

func (a interface{}){

//1st element

if inst,ok:=a.(TypeA); ok{

inst.MethodA()

}

//Second item

switch inst:=a.(type){

case TypeA:

inst.MethodA()

default:

fmt.Println(“unknow”)

}

}

may be any type

a.(some kind of man) returns two or more values inst and ok, meaning whether or not this type of man, or if inst is the type of man

a.(type) type is a comma-separated string using

TypeA(a) is forced to translate

Similar Posts: