```
var fi interface{}
fi = func(){
fmt.Println("jjjjj")
}
switch f := fi.(type){
case bool:
fmt.Println("func",f)
case interface{}:
fmt.Println("interface",f)
// f() // 直接调用会报错cannot call non-function f (type interface {})
default:
fmt.Printf("unknown:%#v\n",f)
}
```
如上代码,fi这个接口变量被赋值为一个函数,如何把这个函数取出来调用呢?
增加一个case func()分支就可以,放在interface分支上面
```go
package main
import (
"fmt"
)
var fi interface{}
func main() {
fi = func() {
fmt.Println("jjjjj")
}
//直接调用
fi.(func())()
switch f := fi.(type) {
case bool:
fmt.Println("func", f)
case func():
f()
case interface{}:
fmt.Println("interface", f)
default:
fmt.Printf("unknown:%#v\n", f)
}
}
```
#1