package main
import (
"fmt"
"reflect"
)
func main() {
type t struct {
N int
}
var n = t{42}
fmt.Println(n.N)
reflect.ValueOf(&n).Elem().FieldByName("N").SeTint(7)
fmt.Println(n.N)
}
下面的编程工作的问题是如何用time.Time类型像这样做
package main
import (
"fmt"
"reflect"
)
func main() {
type t struct {
N time.Time
}
var n = t{ time.Now() }
fmt.Println(n.N)
reflect.ValueOf(&n).Elem().FieldByName("N"). (what funC) (SeTint(7) is only for int) // there is not SetTime
fmt.Println(n.N)
}
这很重要,因为我打算在通用结构上使用它
我真的很感谢你对此的帮助