相关疑难解决方法(0)

是否可以在 Go 中比较两个接口值?

例如:

func compare(a interface{}, b interface{}) {
    if a > b {
        fmt.Printf("%v is bigger than %v", a, b)
    }
}

Run Code Online (Sandbox Code Playgroud)

但最后,我得到了编译器错误:

cannot compare a > b (operator > not defined for interface{})compiler

Run Code Online (Sandbox Code Playgroud)

interface go

1
推荐指数
1
解决办法
793
查看次数

标签 统计

go ×1

interface ×1