The ability to define an anonymous implementation of an interface using anonymous functions, similar to the pseudo code:
RandomNumOp({ Binary: func(a,b int) int { return a+b}, Ternary: func(a,b,c int) int {return a+b+c}, })
is not directly supported in Go. Here are some possible approaches, depending on whether the implementation is required to work:
The above is the detailed content of Can Go Implement Interfaces Anonymously?. For more information, please follow other related articles on the PHP Chinese website!