什么是 Golang Comparable Types

Golang 中有很多时候要用到comparable types,例如比较struct的时候,例如map里的 key。弄清楚有哪些类型是comparable的非常重要。

https://golang.org/ref/spec#Comparison_operators

  • Boolean values
  • Integer values
  • Floating point values
  • Complex values
  • String values
  • Pointer values
  • Channel values
  • Interface values
  • Struct values are comparable if all their fields are comparable
  • Array values are comparable if values of the array element type are comparable
  • A value x of non-interface type X and a value t of interface type T are comparable when values of type X are comparable and X implements T

更多文章
  • YouCompleteMe ycmd server SHUTDOWN 和 pyenv的问题
  • Docker组件介绍(一):runc和containerd
  • Prometheus MySQL Exporter源码阅读与分析
  • MySQL性能指标
  • 使用Dropbox来备份服务器文件
  • 《计算机网络-系统方法》读书笔记
  • Y Combinator《如何创业》笔记
  • Go类型嵌套
  • etcd源码阅读与分析(五):mvcc
  • etcd源码阅读与分析(四):lease
  • 干了这碗叔本华牌毒鸡汤 --- 《人生的智慧》
  • etcd源码阅读与分析(三):wal
  • Memory leak in net/http
  • etcd源码阅读与分析(二):raft
  • etcd源码阅读与分析(一):raftexample