Questions tagged «hashcode»

哈希码是对数据应用哈希函数的结果,通常是整数。

10
在子类中覆盖equals()和hashCode()……考虑到超级字段
关于如何考虑超字段的子类中的Override equals()&hashCode()in,是否有特定规则?知道有很多参数:超字段是private / public,有/没有getter ... 例如,Netbeans生成的equals()和hashCode()不会考虑超级字段...和 new HomoSapiens("M", "80", "1.80", "Cammeron", "VeryHot").equals( new HomoSapiens("F", "50", "1.50", "Cammeron", "VeryHot")) 将返回true :( public class Hominidae { public String gender; public String weight; public String height; public Hominidae(String gender, String weight, String height) { this.gender = gender; this.weight = weight; this.height = height; …

6
包含自身作为元素的ArrayList的哈希码
我们可以发现hashcode的list是本身含有的element? 我知道这是一个坏习惯,但这就是面试官的要求。 当我运行以下代码时,它抛出StackOverflowError: public class Main { public static void main(String args[]) { ArrayList<ArrayList> a = new ArrayList(); a.add(a); a.hashCode(); } } 现在,我有两个问题: 为什么会有一个StackOverflowError? 是否可以通过这种方式找到哈希码?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.