方法集
method receivers |
Values |
(t T) |
T and *T |
(t *T) |
*T |
Values |
method receivers |
T |
(t T) |
*T |
(t T) and (t *T) |
package main
import "fmt"
type User struct {
name string
age int
}
func main() {
user := User{name: "dick", age: 18}
uP := &User{name: "dick", age: 18}
receiver(user)
receiver(*uP)
fmt.Println("============")
receiverPoint(uP)
}
func receiver(user User) {
fmt.Println("receiver name:", user.name, " age:", user.age)
}
func receiverPoint(user *User) {
fmt.Println("receiverPoint name:", user.name, " age:", user.age)
}
网友评论