相关疑难解决方法(0)

关键字var后面的下划线和接口名称是什么意思?

来自http://golang.org/src/pkg/database/sql/driver/types.go :

type ValueConverter interface {
    // ConvertValue converts a value to a driver Value.
    ConvertValue(v interface{}) (Value, error)
}

var Bool boolType

type boolType struct{}

var _ ValueConverter = boolType{} // line 58

func (boolType) String() string { return "Bool" }

func (boolType) ConvertValue(src interface{}) (Value, error) {....}
Run Code Online (Sandbox Code Playgroud)

我知道ValueConverter是一个接口名称.第58行似乎声明boolType实现接口ValueConverter,但这是必要的吗?我删除了第58行,代码运行良好.

syntax interface go underscores

66
推荐指数
2
解决办法
1万
查看次数

标签 统计

go ×1

interface ×1

syntax ×1

underscores ×1