我发现了一个奇怪的行为。我正在使用 JDK 1.7
。
当我打印 map.containsValue(null)
虽然我的 MAP 中没有任何空值,但它返回 true
。
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));
}
}
最佳答案
这是 openjdk 实现中的一个错误。 Consider this link
理想情况下它应该只给出 false See this 1.7 SE
它说 Returns: true if this map maps one or more keys to this value
对我来说它给出 false
- 在 JRE1.7.0_55 上运行
关于java - EnumMap.containsValue(null) 返回真 JDK 7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28737815/