瞬間、私はこのコードでこだわっている:https://play.golang.org/p/r_HEVmpOuDパニック:インタフェース変換:objがObjInterfaceではありません:欠落している方法X
package main
import "fmt"
type (
Collection struct {
Id string
}
CollectionInterface interface {
Process(...string)
}
)
func (this *Collection) Process(params ...string) {
this.Id = "ok"
}
func testfunc(input interface{}) CollectionInterface {
inputCol := input.(CollectionInterface)
inputCol.Process()
return inputCol
}
func makeInterface(input interface{}) interface{} {
return input
}
func main() {
test := Collection{Id: "ya"}
test.Process()
testInt := makeInterface(test)
test0 := testInt.(CollectionInterface)
test1 := testfunc(test0)
fmt.Println(test1)
}
私はちょうど私がに} {インターフェイスに変換することができますどのように思ったんだけど"Process"関数を静的関数に変更せずにCollectionInterface?
31行目に '&'を追加すると、コレクションはコレクションインターフェイスを実装しません(*コレクションのみ)。そして、もう一度Goのツアーに参加してください。 – Volker
私は実際には反射からインターフェイスを取得している、私はちょうどそのポインタを取得する方法がAdd()。Interface()関数を使用していることがわかった。私はそれがリフレクションインターフェイスのためのポインタを得るために立ち往生した人々に役立つことを望む。 –