给定一个返回指针类型切片但包装为接口类型的接口。是否可以修改值?
type Base interface {
Do()
}
type Meta interface {
Base
Children() []Base
}
type A struct {
}
func (a *A) Do() {
}
type B struct {
children []Base
}
func (b *B) Children() []Base {
return b.children
}
如果代码以如下方式初始化:
a := &A{}
b := &B{children: []Base{a}}
是否可以B.children
仅用调用后返回的值b.Children()
和使用反射来覆盖值?或者那不可能?