var ( _ ConnWithTimeout = (*conn)(nil) )
原代码链接
看 redigo 源码,发现文件开头定义了个 _ 只读的变量,一头懵~~
_
求助:作者为啥这么写?
有疑问加站长微信联系(非本文作者)
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
求助,有大神解答下么?
来确保 conn 实现了 ConnWithTimeout 接口。
conn
来确保 `conn` 实现了 ConnWithTimeout 接口。
@polaris 没实现接口不是会在编译的时候报错么?没必须去确认吧?
我看代码和尝试后也觉得是确保实现了,但是觉得编译会报错,没必要加这个确认
没实现,自然编译报错,就是为了编译期就能确保实现了某个接口
5楼 @polaris 了解了!
【报错】是在加这行代码才出现的。
感谢。>_<
cannot use (conn)(nil) (type conn) as type ConnWithTimeout in assignment: *conn does not implement ConnWithTimeout (wrong type for Do method) have Do(string, ...interface {}) (interface {}, error) want Do(string) 是不是reids源码有问题 怎么解决的
`单行代码`
求助,有大神解答下么?
来确保
conn
实现了 ConnWithTimeout 接口。@polaris 没实现接口不是会在编译的时候报错么?没必须去确认吧?
我看代码和尝试后也觉得是确保实现了,但是觉得编译会报错,没必要加这个确认
没实现,自然编译报错,就是为了编译期就能确保实现了某个接口
5楼 @polaris 了解了!
【报错】是在加这行代码才出现的。
感谢。>_<
cannot use (conn)(nil) (type conn) as type ConnWithTimeout in assignment: *conn does not implement ConnWithTimeout (wrong type for Do method) have Do(string, ...interface {}) (interface {}, error) want Do(string) 是不是reids源码有问题 怎么解决的