Created
July 9, 2012 02:07
-
-
Save hantuo/3073832 to your computer and use it in GitHub Desktop.
golang dynamic type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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