// iface 是一个接口类型的变量
if foo, ok := iface.(interface { ... method set ... }); ok {
... use methods ...
}
使用 Type switches
// iface 是一个接口类型的变量
switch x := iface.(type) {
case interface{ ... method set ... }:
... use methods ...
case interface{ ... method set ... }:
... use methods ...
default:
... do something ...
}
interface literal 的写法
使用 Type assertions
使用 Type switches
这种写法的一些参考