golang吧 关注:6,319贴子:14,502
  • 0回复贴,共1

golang实现类型断言

只看楼主收藏回复

package main
import (
. "fmt"
)
func whattype(variable interface{}){ //interface can accept anytype the variable
switch variable.(type) { //create a switch for choose it
case string: // this is one,you can make it for more
Println("this is string type.")
case int:
Println("this is int type.")
case bool:
Println("this is bool type.")
}
}
func main() {
var x string
whattype(x)
}
代码贴上 自己研究


IP属地:山东1楼2020-01-10 11:29回复