【发布时间】:2018-02-16 07:12:52
【问题描述】:
我希望能够为以下结构动态生成方法ApiName:
type SomeCustomSObject struct {
sobjects.BaseSObject
}
我要实现方法的接口如下:
type SObject interface {
ApiName() string
ExternalIdApiName() string
}
我想动态创建方法如下:
func createApiNameMethod(name, string) <return type> {
return func (t *SomeCustomSObject) ApiName() string {
return name
}
}
我知道上面的代码不起作用,但是在 Go 中是否可以实现这一点?
【问题讨论】:
标签: go methods interface closures dispatch