我发现了一个奇怪的行为。我正在使用JDK 1.7
. 当我打印map.containsValue(null)
true
尽管我的 MAP 中没有任何空值,但它会返回。
import java.util.EnumMap;
import java.util.Map;
public class EnumMapTest {
enum EnumType {
ZERO, ONE, TWO
}
public static void main(String[] args) {
Map<EnumType, Integer> map = new EnumMap<EnumType, Integer>(EnumType.class);
map.put(EnumType.ZERO, 0);
System.out.println(map.containsValue(null));
}
}