invalid interface type and num
时间: 2024-02-02 12:04:39 浏览: 262
ber of arguments in function declaration.
This error occurs when the interface type and the number of arguments in the function declaration do not match.
For example, suppose we have the following interface:
```
type MyInterface interface {
MyMethod(arg1 string, arg2 int) string
}
```
And we have a function that implements this interface:
```
func MyFunc(arg1 string) string {
return arg1
}
```
In this case, we will get an "invalid interface type and number of arguments in function declaration" error because the function `MyFunc` only takes one argument, whereas the interface method `MyMethod` takes two arguments.
To fix this error, we need to make sure that the function declaration matches the interface method declaration. In this case, we need to add another argument to `MyFunc`:
```
func MyFunc(arg1 string, arg2 int) string {
return arg1
}
```
阅读全文