Created
April 30, 2012 15:20
-
-
Save dcolish/2559192 to your computer and use it in GitHub Desktop.
Interfaces are fun
This file contains hidden or 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 test of the interface types and how they may be passed | |
| package main | |
| import "fmt" | |
| type A interface { | |
| Action() | |
| } | |
| type C interface { | |
| A | |
| isOk() (bool) | |
| } | |
| type B struct { | |
| okness bool | |
| } | |
| func (* B) Action() { | |
| fmt.Println("HELLO") | |
| } | |
| func (p *B) isOk() (bool) { | |
| return p.okness | |
| } | |
| func callToAction (p C) { | |
| p.Action() | |
| } | |
| func main () { | |
| b := B{false} | |
| if b.isOk() { | |
| callToAction(&b) | |
| } else { | |
| println("This is not ok") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment