Skip to content

Instantly share code, notes, and snippets.

@hantuo
Created July 9, 2012 02:07
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hantuo/3073832 to your computer and use it in GitHub Desktop.
Save hantuo/3073832 to your computer and use it in GitHub Desktop.
golang dynamic type
package main
type I interface {
Foo()
}
type A struct {
}
func (p *A) Foo() {}
type B struct {
}
func (p *B) Foo() {}
func F(i I) {
i.Foo() // dynamic type
}
func main() {
a := A{}
b := B{}
F(a)
F(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment