package main
import(
"fmt"
)
type A func (int,int)
func (this A) Serve() {
fmt.Println("function 1")
}
func Serve(int,int) {
fmt.Println("function 2")
}
func main() {
a := A(Serve)
a.Serve() // function 1
}
Function Serve can be converted to type A,which is also a function,but,I just don't get the idea of when and why we should use this approach,to deal with what kind of problem should we convert a function type to another?My example seems to be meaningless.
int,struct etc. are types,and what exactly is the function type different from the common known types like int and struct,from the underlying data structure perspective of view?
Thanks a lot!