Created
May 19, 2019 14:24
-
-
Save josephspurrier/25d2ee03833a1e6eab33cc9b49956515 to your computer and use it in GitHub Desktop.
Method Overriding 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
package main | |
import "fmt" | |
type foo struct{} | |
func (f foo) Start() { | |
fmt.Println("Foo Started") | |
} | |
func (f foo) Call() { | |
fmt.Println("Foo Called") | |
} | |
func (f baz) Call() { | |
fmt.Println("Baz Called") | |
} | |
type baz struct { | |
foo | |
} | |
func main() { | |
foo{}.Call() // This output: Foo Called | |
foo{}.Start() // This output: Foo Started | |
baz{}.Call() // This outputs: Baz Called | |
baz{}.Start() // This outputs: Foo Started | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment