关于java 的
题目如下 public class Person { private String name,comment; private int age; public Person(String n ,int a, String c) { name = n; age = a; comment = c; } public boolean equals(Object o) { if(!(o instanceof Person)) return false; Person p = (Person) o; return age == p.age && name.equals(p.name); } } what is the appropriate definition of the hashCode method in class Person? A return super.hashCode(); B return name.hashCode() + age * 7; C return name.hashCode() + comment.hashColde()/2; D return name.hashCode() + comment.hashColde()/2 - age * 3; 请高手解析一下这道题 答案是B
很显然是B 看看equals的实现,仅仅是判断了年龄和姓名就确定是相等的 因此hashcode只能对age和name两个属性进行处理 A、C和D是不合适的
答:google "java 缓冲池"详情>>
答:百度里搜张孝祥 非常好的视频教程详情>>