Skip to content

Instantly share code, notes, and snippets.

@tmtk75
Created June 8, 2014 12:47
Show Gist options
  • Save tmtk75/cb4564665fd2308a9a70 to your computer and use it in GitHub Desktop.
Save tmtk75/cb4564665fd2308a9a70 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Human struct {
Age int
Name string
Walk func(place string)
}
func (h Human) String() string {
return fmt.Sprintf("%s[%d]", h.Name, h.Age)
}
func (h Human) Run(distance int) {
fmt.Printf("%s run %dm\n", h, distance)
}
func (h Human) Dash(distance int) {
fmt.Printf("%s dash %dm\n", h, distance)
}
type Runner interface {
Run(distance int)
Dash(distance int)
}
func Goal(r Runner) {
r.Run(10)
r.Dash(50)
}
type Kid struct {
Human
School string
}
type Athlete interface {
Runner
}
func main() {
a := Human{Age: 10}
b := Kid{Human{Age: 20}, School: "Jingu"}
Goal(a)
Goal(b)
}
@tmtk75
Copy link
Author

tmtk75 commented Jun 8, 2014

$ go run mixture-of-field.go 
# command-line-arguments
./mixture-of-field.go:44: mixture of field:value and value initializers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment