package main
import (
"fmt"
"reflect"
)
type student struct {
name string
}
type GetInfo interface {
GetName() string
SetName(name string)
}
func (stu *student) GetName() string {
return (*stu).name
}
func (stu *student) SetName(name string) {
stu.name = name
}
func main() {
var info GetInfo
var joe student
info = &joe
info.SetName("China")
fmt.Println("the type of info is :", reflect.TypeOf(info))
fmt.Println("the type of joe is :", reflect.TypeOf(joe))
fmt.Println("the value of info is :", reflect.ValueOf(info))
fmt.Println("the value of joe is :", reflect.ValueOf(joe))
fmt.Println("i come from :", info.GetName())
}
有疑问加站长微信联系(非本文作者)