golang两切片的值比较
按类型比较 (Comparability by type)
Basic data types are always comparable using the ==
and !=
operators: integer values, floating-point numbers, complex numbers, boolean values, string values, constant values.
基本数据类型始终可以使用==
和!=
运算符进行比较: 整数值, 浮点数 , 复数 , 布尔值, 字符串值, 常量值。
Array values are comparable, if they contain a comparable element type
如果数组值包含可比较的元素类型,则可比较
Pointer values are comparable.
指针值是可比较的。
Channel values are comparable.
通道值是可比较的。
Interface values are comparable.
接口值是可比较的。
Comparing interface values works only if the dynamic type is comparable.
仅当动态类型可比较时,比较接口值才有效。
Function values, Slice values and Map values are not comparable, they can only be compared with nil
, as a special case.
函数值, Slice值和Map值不可比较,在特殊情况下只能与nil
进行比较。
比较规则 (The rules of comparison)
From the Go spec:
从Go规范:
Boolean values are comparable. Two boolean values are equal if they are either both
true
or bothfalse