这是代码,我预计访问 mp["12"] 时会出现恐慌,但它在那里工作正常
// You can edit this code! // Click here and start typing. package main import "log" func main() { var mp map[string]int = nil log.Println(mp["12"], "12") // works fine if mp == nil { panic("map is nil") // panic here } }
您可以从 nil 映射中读取,但无法写入。语言规范说:
以上就是为什么 Go 在尝试读取 nil 映射时不会恐慌?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号