OnJava8-Examples/staticchecking/dogsandrobots.go
2016-12-30 17:23:13 -08:00

28 lines
569 B
Go

// staticchecking/dogsandrobots.go
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.
package main
import "fmt"
type Dog struct {}
func (this Dog) talk() { fmt.Printf("woof!\n")}
func (this Dog) reproduce() {}
type Robot struct {}
func (this Robot) talk() { fmt.Printf("Click!\n") }
func (this Robot) oilChange() {}
func speak(speaker interface { talk() }) {
speaker.talk();
}
func main() {
speak(Dog{})
speak(Robot{})
}
/* Output:
woof!
Click!
*/