要打开
*foo到一个
interface{}很简单:f := &foo{}bar(f) // every type implements interface{}. Nothing special required为了返回到
*foo,您可以执行 类型断言 :
func bar(baz interface{}) { f, ok := baz.(*foo) if !ok { // baz was not of type *foo. The assertion failed } // f is of type *foo}或 类型开关
(类似,但
baz可以是多种类型则很有用):
func bar(baz interface{}) { switch f := baz.(type) { case *foo: // f is of type *foo default: // f is some other type }}


