代码如下:
```go
package main
import (
"fmt"
)
type Task struct {
f func(i interface{})
}
func NewTask(h func(interface{})) (t *Task) {
t = &Task{
f: h,
}
return
}
func (t *Task) Run() {
fmt.Println("Runing...")
}
func test1(i *int) error {
fmt.Println("test1", i)
// do something here
// ...
return nil
}
func test2(s *string) (err error) {
fmt.Println("test2", s)
// do otherthing here
// ...
return
}
func main() {
t1 := NewTask(test1)
t2 := NewTask(test2)
t1.Run()
t2.Run()
}
```
报错:
.\main.go:33:15: cannot use test1 (type func(*int) error) as type func(interface {}) in argument to NewTask
.\main.go:34:15: cannot use test2 (type func(*string) error) as type func(interface {}) in argument to NewTask
请教诸位如何修改?谢谢
有疑问加站长微信联系(非本文作者)