Skip to content

Instantly share code, notes, and snippets.

@maxwellgithinji
Created July 27, 2020 09:13
Show Gist options
  • Save maxwellgithinji/e9bc00861fded97cf667fb22591f462e to your computer and use it in GitHub Desktop.
Save maxwellgithinji/e9bc00861fded97cf667fb22591f462e to your computer and use it in GitHub Desktop.
// type *T
// The method set of the corresponding pointer type *T is the set of all methods declared with receiver *T or T (that is, it also contains the method set of T).
package main
import (
"fmt"
)
type Person struct {
first string
}
type secretAgent struct {
Person
ltk bool
}
func (p *Person) speak() {
fmt.Println("from person", p.first)
}
func (sa *secretAgent) speak() {
fmt.Println("from secret agent", sa.first)
}
type human interface {
speak()
}
func saySomething(h human) {
h.speak()
}
func main() {
p1 := Person{
first: "Jorgen",
}
sa1 := secretAgent{
Person: Person{
first: "Ula Britta Frita Smirta",
},
ltk: true,
}
saySomething(&p1)
saySomething(&sa1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment