type Student struct {
id int,
name string,
}
//If I create two structs,
s := Student{1, "jack"}
t := Student{1, "jack"}
m := make(map[Student]bool)
m[s] = true
m[t] = true
1)可以吗?2)在Golang中是否有类似于Java的hashCode?
如果两个结构值具有相同的成员值,并且所有这些成员都是可比较的,则这些结构相等。在您的示例中:s==t
是true
。结构值本身就是映射键。因此,在您的示例中,地图的末尾只有一个元素。
有关可比性的更多信息:
https://golang.org/ref/spec#Comparison_operators
hashCode
Go中没有等效项。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句