【发布时间】:2012-06-06 18:35:26
【问题描述】:
我正在编写一个 Android 应用程序并使用 HashMap<String,MyClass>。根据 Java 和 Android 文档,HashMap 应该接受空键和空值。但是,奇怪的是,我不能将 null 值放入我的地图中。在代码中:
myMap.put(1, null);
我收到了错误:
The method put(String, MyClass) in the type HashMap<String,MyClass> is not applicable for the arguments (int, null).
这是为什么呢?有什么问题以及如何解决?
【问题讨论】:
-
你只需要先看一下语言的基础,然后来这里。