Here’s a silly example extracted from real code.
package main
import "fmt"
type Location int
const (
KITCHEN Location = iota
BATHROOM
)
type Ingredient struct {
name string
location Location
}
func (i *Ingredient) Location() *Location {
return &i.location
}
func main() {
sausage := Ingredient{name: "bratwurst", location: KITCHEN}
legume := Ingredient{name: "chic pea", location: KITCHEN}
fmt.Println(sausage.Location() == legume.Location())
}
Does this program print true or false?
Pages: 1 2