redfin的Agent有人用过吗# Living
S*C
1 楼
今天面试一个挺高大上的公司,一个韩国面试官让我实现一个HashMap class
我把Entry写成 static inner class
他说应该写成 static inner interface
但HashMap JDK 源代码中的确是写成 static inner class来implement Map.Entry
inner interface的,这个面试官根本没看过源代码,他说要写成static inner
interface的原因仅仅是他找到存在Map.Entry这个interface的api
还有一个问题,我写了一个简洁的hashcode()方法
private int hash(K key){
int hashcode = key.hashCode();
return hashcode > 0 ? hashcode % table.length : -hashcode % table.
length;
}
他说hash怎么可能是负的,为什么要写这个判断语句
实际上
sometimes the hashcode calculation itself goes beyond the Integer.MAX_VALUE,
i.e 2147483647. what happens then is
that we get a negative integer after the overflow. Negative hashcode is
perfectly valid!
当然面试官知道一些我不知道的东西
我把Entry写成 static inner class
他说应该写成 static inner interface
但HashMap JDK 源代码中的确是写成 static inner class来implement Map.Entry
inner interface的,这个面试官根本没看过源代码,他说要写成static inner
interface的原因仅仅是他找到存在Map.Entry这个interface的api
还有一个问题,我写了一个简洁的hashcode()方法
private int hash(K key){
int hashcode = key.hashCode();
return hashcode > 0 ? hashcode % table.length : -hashcode % table.
length;
}
他说hash怎么可能是负的,为什么要写这个判断语句
实际上
sometimes the hashcode calculation itself goes beyond the Integer.MAX_VALUE,
i.e 2147483647. what happens then is
that we get a negative integer after the overflow. Negative hashcode is
perfectly valid!
当然面试官知道一些我不知道的东西