Created
March 2, 2014 07:07
-
-
Save rolaveric/9303031 to your computer and use it in GitHub Desktop.
Example of implicit interface implementations in Go
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
// A Doer is anything that will Do something | |
type Doer interface { | |
Do() | |
} | |
// X needs a Doer | |
func X(doer Doer) { | |
doer.Do() | |
} | |
// Y will Do something, and is therefore a Doer | |
type Y string | |
func (y Y) Do() { | |
// Does something | |
} | |
func main() { | |
var y Y = "meep" | |
X(y) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment