昨天在测试的时候,发现如下代码报 : Exception in thread "main" java.lang.NullPointerException
Map<Integer,Integer> intMap = new HashMap<Integer,Integer>();
intMap.put(1, 2);
intMap.put(3, 3);
if(intMap.get(2)==2){ //提示异常在此处
// ......
}
突然在想起,Map中的get方法,如果key不存在的话,返回值是null。
以上是昨天犯的低级错误...