GO 八、method
Method
type A struct {
Name string
}
type B struct {
Name string
}
func main() {
a := A{}
a.PrintMe()
}
func (a A)PrintMe(){
fmt.Println("A")
}
func (a *A)PrintMe2(){
a.Name="AA"
fmt.Println("A")
}
// func (a A)PrintMe(b int){
// fmt.Println("A")
// }
type TZ int
func main(){
var a TZ
a.PrintMe() //method value
(*TZ).Print(&a) //method expression
}
func (a *TZ)PrintMe() {
fmt.Println("TZ")
}