Please first have a look at the code below.
package main
import "fmt"
type InterfaceFunc func(interface{})
type StringFunc func(string)
func stringFunc(s string) {
fmt.Printf("%v", s)
}
func interfaceFunc(i interface{}) {
fmt.Printf("%v", i)
}
func main() {
var i = interfaceFunc
var s = stringFunc
i = s // I would like someone to explain why this can't be done exactly.
}
Run at https://play.golang.org/p/16cE4O3eb95
Why an InterfaceFunc
can't hold a StringFunc
while an interface{}
can hold a string
.
You can not do s = i
or i = s
, and the reason is both functions are of different type (different signatures), you can not just assign one type with another in golang.
Also type InterfaceFunc func(interface{}) type StringFunc func(string)
are sitting there doing nothing.