I'm passing objects of two different structs to a function where it's compared with an existing object saved as interface {}
type.
In the following how can I make two objects comparable for Equality ===
In this attempt, comparison with bar works fine but with foo it throws a panic error in spite both objects are of struct type
package main
import "fmt"
type Foo struct {
TestMethod func(str string)
}
type Bar struct {}
type IQux interface {
Compare(object interface{}) bool
}
type Qux struct {
Method func(str string)
Reference interface{}
}
func (qux Qux) Compare(object interface{}) bool {
return object == qux.Reference
}
func testMethod(str string) {
fmt.Println(str)
}
func main() {
foo := Foo{TestMethod:testMethod}
bar := Bar{}
ob := &Qux{Method: foo.TestMethod, Reference: foo}
ob.Compare(bar) // works fine
ob.Compare(foo) // panic: runtime error: comparing uncomparable type main.Foo
}