【发布时间】:2016-11-18 13:59:43
【问题描述】:
根据其内容计算 Array 的 hashCode 的合适方法是什么?
Array.hashCode 用于数组实例:
val h = a.hashCode
println(h == Array(1,2).hashCode) // false
a(0) = 42
println(h == a.hashCode) // true
注意:在计算 hashCode 之前最好避免将整个数组复制到列表中
为什么问:我在类中使用数组(作为私有字段),因为查找时间很关键,并且它的内容与计算类的 hashCode 相关
【问题讨论】: