对go语法感到困惑 [英] Confused about go syntax
本文介绍了对go语法感到困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
与此代码有些混淆.
var _ QueryAppender = (*selectQuery)(nil)
我在 pg-go 存储库,不知道为什么 QueryAppender
这样声明.请向我解释以这种方式声明变量的用例是什么.
I found this code in pg-go
repository and don't know why QueryAppender
declared that way. Please explain me what is the use cases when I should declare variables that way.
推荐答案
这在运行时不会执行任何操作,但是除非 * selectQuery
类型满足接口 QueryAppender
,编译将失败.这是一种静态断言.
This doesn't do anything at runtime, but unless the *selectQuery
type satisfies the interface QueryAppender
, compilation will fail. It's a kind of static assertion.
这篇关于对go语法感到困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文