【发布时间】:2020-09-12 16:41:44
【问题描述】:
我尝试像这样迭代 EntrySet:
for (Entry<A, List<B>> list : service.entrySet()) {
if (list.getKey() == typ1) {
for (B current : list.getValue()) {
// do sth
}
}
} else {
PrintHelper.printOut("not implemented case"
+ list.getKey());
}
}
}
即使我有那部分 if (list.getKey() == typ1) 我仍然得到印刷案例not implemented case typ1。
为什么会这样?我在迭代/ if 案例中做错了什么?
【问题讨论】:
-
是
typ1和list.getKey()的返回值字符串,还是任何类型的对象?如果是这样,请将它们与equals()进行比较,而不是与 '==' 进行比较。