Last active
August 29, 2015 14:21
-
-
Save djmitche/b3ffbb9d4b1d79105106 to your computer and use it in GitHub Desktop.
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
| package main | |
| import "fmt" | |
| type Executer interface { | |
| Show() | |
| } | |
| type executer struct { | |
| b int | |
| } | |
| func (e executer) Show() { | |
| fmt.Printf("Hi, b is %d", e.b) | |
| } | |
| type Moduler interface { | |
| NewRun() Executer | |
| } | |
| type moduler struct { | |
| a int | |
| } | |
| func (m moduler) NewRun() Executer { | |
| return executer{m.a * 10} | |
| } | |
| var current *Moduler | |
| func main() { | |
| current = moduler{7} | |
| run := (*current).NewRun() | |
| run.Show() | |
| } |
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
| ./pointer.go:32: cannot use moduler literal (type moduler) as type *Moduler in assignment: | |
| *Moduler is pointer to interface, not interface |
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
| package main | |
| import "fmt" | |
| type Executer interface { | |
| Show() | |
| } | |
| type executer struct { | |
| b int | |
| } | |
| func (e executer) Show() { | |
| fmt.Printf("Hi, b is %d", e.b) | |
| } | |
| type Moduler interface { | |
| NewRun() Executer | |
| } | |
| type moduler struct { | |
| a int | |
| } | |
| func (m moduler) NewRun() Executer { | |
| return executer{m.a * 10} | |
| } | |
| var current Moduler | |
| func main() { | |
| current = moduler{7} | |
| run := current.NewRun() | |
| run.Show() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment