Golang 1.17.x 空指针类 能正常调用类方法

xiaoyi510 · · 894 次点击
jan-bar
想要拥有,必定付出。
根据官方祖传代码显示,go天生就这样吧。 ```go // Close closes the File, rendering it unusable for I/O. // On files that support SetDeadline, any pending I/O operations will // be canceled and return immediately with an error. // Close will return an error if it has already been called. func (f *File) Close() error { if f == nil { return ErrInvalid } return f.file.close() } ```
#4
更多评论
![image.png](https://static.studygolang.com/211230/0e67a319d05c3b6e07ce90bf28b7a053.png) 不对 我使用1.16.5也不报错 朋友的go就报错 ![image.png](https://static.studygolang.com/211230/37e9d1251c23e52ec474e770b487b4ad.png)
#1
``` func (this *A) Test() string { return "123" } ``` 不报错 报错 此报错我觉得是正常的毕竟没实例化 ``` func (this A) Test() string { return "123" } ```
#2