Confused about go syntax [duplicate]

2020-01-20 11:42发布

Little bit confused with this code.

var _ QueryAppender = (*selectQuery)(nil)

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.

标签: go
1条回答
Fickle 薄情
2楼-- · 2020-01-20 12:22

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.

查看更多
登录 后发表回答