小编Mat*_*u L的帖子

HashMap中的keySet字段为null

我试图HashMap用如下keySet()方法循环:

for (String key : bundle.keySet()) {
    String value = bundle.get(key);
    ...
}
Run Code Online (Sandbox Code Playgroud)

我用了很多的for-each上HashMaps这样的循环在我的代码其他部分,但是这一次作为一个怪异的行为:它的大小为7(什么是正常的),但是keySet,entrySetvaluesnull(根据Eclipse调试器)!

"bundle"变量被实例化并填充如下(没有原始...):

Map <String, String> privVar;
Constructor(){
    privVar = new HashMap<String, String>();
}
public void add(String key, String value) {
    this.privVar.put(key, value);
}
Run Code Online (Sandbox Code Playgroud)

java collections hashmap map

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

collections ×1

hashmap ×1

java ×1

map ×1