Last active
March 7, 2018 15:59
-
-
Save RitterHou/f7a5fb34a9572d58638a56bbcabb8105 to your computer and use it in GitHub Desktop.
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 | |
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