package main
import “fmt”
type mystring string
func (self mystring)String()string{
return string(self)
}
func (self mystring) show(){
self = “hi”
fmt.Println(self)
}
func (self *mystring) show2(){
*self = “hi”
fmt.Println(self)
}
func main(){
var str = mystring(“hello”)
var pstr = &str
str.show()
fmt.Println(str)
//str.show2() panic
pstr.show()
fmt.Println(str)
pstr.show2()
fmt.Println(str)
}
有疑问加站长微信联系(非本文作者)