请考虑以下代码:
import java.util.*;
class Employee {
String name;
public Employee(String nm) {
this.name=nm;
}
}
public class HashMapKeyNullValue {
Employee e1;
public void display(){
Employee e2=null;
Map map=new HashMap();
map.put(e2, "25");
System.out.println("Getting the Value When e2 is set as KEY");
System.out.println("e2 : "+map.get(e2));
System.out.println("e1 : "+map.get(e1));
System.out.println("null : "+map.get(null));
map.put(e1, "");
System.out.println("Getting the Value when e1 is set as KEY");
System.out.println("e2 : "+map.get(e2));
System.out.println("e1 : "+map.get(e1));
System.out.println("null : "+map.get(null));
map.put(null, null); // null as key and null as value
System.out.println("Getting …Run Code Online (Sandbox Code Playgroud) 我刚刚阅读了Java中HashMap和HashTable类之间的区别.在那里,我发现前者允许空键以及后来不具有相同权限的区别.就HashMap的工作而言,我知道,它在key上调用hashcode方法来查找要放置该键值对的存储区.这是我的问题:如何计算空值的哈希码或是否有空键的哈希码的默认值(如果是这样请指定值)?