Skip to content

Instantly share code, notes, and snippets.

@RitterHou
Last active March 7, 2018 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RitterHou/f7a5fb34a9572d58638a56bbcabb8105 to your computer and use it in GitHub Desktop.
Save RitterHou/f7a5fb34a9572d58638a56bbcabb8105 to your computer and use it in GitHub Desktop.
package main
type animal interface {
say()
work()
}
type dog struct {
}
type cat struct {
}
func (self dog) say() {
println("i am a dog")
}
func (self *dog) work() {
println("dog is working")
}
func (self cat) say() {
println("i am a cat")
}
func (self *cat) work() {
println("cat is working")
}
func main() {
d := new(dog)
d.say()
d.work()
d1 := *d
d1.say()
d1.work()
c := new(cat)
c.say()
c.work()
c1 := *c
c1.say()
c1.work()
println("=================")
doit(d)
// doit(d1)
println(">>>>>>>>>>>>>>>>>>")
doit(c)
}
func doit(a animal) {
a.say()
a.work()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment