Closed zzBeeCoder closed 3 months ago
go 1.20 gomonkey v2.1.0
type AbstractCall[T any] struct { } func (m *AbstractCall[T]) Call(a T) string { return "abstract call" } func main() { defer gomonkey.ApplyMethod(reflect.TypeOf(&AbstractCall[string]{}), "Call", func(_ *AbstractCall[string], a string) string { return "gomonkey call:" + a }).Reset() m := &AbstractCall[string]{} fmt.Println("call:" + m.Call("aa")) }
范型的支持可以参考xgo实现:https://github.com/xhd2015/xgo
参考作者文章:https://www.jianshu.com/p/8a52eae7f786
go 1.20 gomonkey v2.1.0