//heihei
第一种方法是检细节的地方问:比如在java中,
int i = 0xf000;
i = i>>> 64;
问现在 i 是多少?
又如:c1的定义如下:
class c1{
int i;
public c1(int i){
this.i = i;
}
public boolean equals(Object obj){
return true;
}
}
那么下面的程序段执行后的结果是多少?
java.util.Hashtable ht = new java.util.Hashtable();
c1 key1 = new c1(1);
c1 key2 = new c1(2);
ht.put(key1,key2);
ht.put(key2
l**e 发帖数: 97
2
今天拿着第一题去 Interview 了一个 candidate,
他回答 false,我以为他答错了。结果回来用电脑
验算一遍,才发现他是对的。
其实原题的 class c1 应该定义如下:
class c1{
int i;
public c1(int i){
this.i = i;
}
public int hashCode ()
{ return 0; } // or return any defined integer number here
public boolean equals(Object obj){
return true;
}
}
如果不定义 c1::hashCode(),Java 给出的结果就是 false。
但如果定义了 c1::hashCode(),Java 就会给出 true 了。
java.util.Hashtable 的 put 和 get 都会首先求出调用
【在 b**o 的大作中提到】 : //heihei : 第一种方法是检细节的地方问:比如在java中, : int i = 0xf000; : i = i>>> 64; : 问现在 i 是多少? : 又如:c1的定义如下: : class c1{ : int i; : public c1(int i){ : this.i = i;