【发布时间】:2020-04-15 06:48:42
【问题描述】:
面试官问这个问题,大多数与哈希码相关的答案都用于分桶,它检查等于搜索对象。
是否有任何其他一般用例或场景,其中哈希码是有益的并且可以在常规程序中使用?
最近我使用了JPA,它抛出异常"Composite-id class does not override hashCode()",但它再次被hibernate的实现类使用。 Sly,除了集合,我们还可以在哪些其他地方或场景中使用哈希码,尤其是您自己使用过的场景。
class a {
public int hashCode() {
}
}
class b {
public static void main(String[] str) {
//In what ways can i use hashcode here?
}
}
【问题讨论】:
标签: java hashmap hashcode hash-code-uniqueness