Created
October 10, 2014 00:35
-
-
Save bbengfort/e54e8c816e4df90feb92 to your computer and use it in GitHub Desktop.
Demonstration of overloading 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 A struct{ | |
name string | |
} | |
func (a *A) method() { | |
fmt.Printf("In method of an A named %s\n", a.name) | |
} | |
type B struct { | |
A | |
} | |
func (b *B) method() { | |
fmt.Printf("In method of an B named %s\n", b.name) | |
(&b.A).method() | |
} | |
func main() { | |
a := A{"apple"} | |
b := new(B) | |
b.name = "banana" | |
a.method() | |
b.method() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment