我有一个名为
ProtectedCustomType
我不希望其中的变量
set
或
get
直接由呼叫者,而是希望
Getter / Setter
方法。
下面是我的
受保护的自定义类型
package custom
import "fmt"
type ProtectedCustomType struct {
name string
age string
phoneNumber int
}
func (pct *ProtectedCustomType) SetAge (age string) {
pct.age=age
fmt.Println(pct.age)
}
func (pct *ProtectedCustomType) GetAge () string {
return pct.age
}
这是我的主要功能
package main
import (
"fmt"
"./custom"
)
var print =fmt.Println
func structCheck2() {
pct := custom.ProtectedCustomType{}
pct.SetAge("23")
age:=pct.GetAge
print (age)
}
func main() {
structCheck2()
}
我想把它印出来
23
,但它正在打印为
0x48b950