V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  SSang  ›  全部回复第 8 页 / 共 8 页
回复总数  143
1  2  3  4  5  6  7  8  
2021-03-19 17:45:04 +08:00
回复了 yujianwjj 创建的主题 Go 编程语言 go 全局变量的一个疑问?
主要是用来保证 interface 的实现是完整的吧,因为如果实例没有完全实现接口是可以编译过去的,但是加了这个就编译不过去了

比如这样是没问题的,但是其实你可能是想要实现 `TestInterface`,这么写也不会给你报错,但和预期结果就不一样了

```go
type TestInterface interface {
func1()
func2()
}

type test struct {
}

func (t *test) func1() {
}
```

这样写就会有报错了

```go
type TestInterface interface {
func1()
func2()
}

var _ TestInterface = test{}

type test struct {
}

func (t *test) func1() {
}
```

```
Cannot use 'test{}' (type test) as type TestInterface Type does not implement 'TestInterface' as some methods are missing: func2()
```
2021-03-15 09:22:24 +08:00
回复了 zealinux 创建的主题 程序员 大家记日记吗?已经快失忆了,记不清这些年干什么了
写博客,写朋友圈就好,正经人谁写日记
挖坟 @littleshy 我之前是所有的配置都导出一份备份到 git 上,确实是每次一改就要备份,很不方便,所以现在我会尽量少地改 IDE 快捷键,不得不改的都记在脑子里,我现在 IDE 就只改一个就是屏蔽 ctrl+p/ctrl+n,其他所有能用 vimrc 配的就用 vimrc,这样至少能够不管换哪个 IDE 我都能用同一份配置(虽然我记得 16 年时候似乎很多 IDE 还不支持用 vimrc )
1  2  3  4  5  6  7  8  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2779 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 22ms · UTC 05:39 · PVG 13:39 · LAX 22:39 · JFK 01:39
Developed with CodeLauncher
♥ Do have faith in what you're doing.