Joda 和 Java lang 整数不兼容
收到此错误:
incompatible types
required: java.lang.Integer
found: java.util.Map.Entry<org.joda.time.DateTime.java.lang.Integer>
以及导致错误的代码:
public static void checkRange() {
DateTime startx = new DateTime(startDate.getTime());
DateTime endx = new DateTime(endDate.getTime());
//produces submap
Map<DateTime, Integer> nav = map.subMap(startx, endx);
//this is the line causing the error:
for (Integer capacity : map.subMap(startx, endx).entrySet()) {
}
}
}
我之前将 startDate 和 endDate 定义为 Date,然后我在此处将它们转换为 DateTime。我不认为这是问题所在 地图是
public static TreeMap<DateTime, Integer> map = new TreeMap<DateTime, Integer>();
谢谢,
Getting this error:
incompatible types
required: java.lang.Integer
found: java.util.Map.Entry<org.joda.time.DateTime.java.lang.Integer>
and the code resulting in error:
public static void checkRange() {
DateTime startx = new DateTime(startDate.getTime());
DateTime endx = new DateTime(endDate.getTime());
//produces submap
Map<DateTime, Integer> nav = map.subMap(startx, endx);
//this is the line causing the error:
for (Integer capacity : map.subMap(startx, endx).entrySet()) {
}
}
}
I have startDate and endDate defined as Date earlier then I convert them here as u can see to DateTime. I dont think that's the problem
and the map is
public static TreeMap<DateTime, Integer> map = new TreeMap<DateTime, Integer>();
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
entrySet()
返回映射的“行”,即包含键和值的Entry
对象。要仅迭代值,您可以使用map.values()
,在本例中它是Integer
的集合。The
entrySet()
returns the "rows" of the map, that is, theEntry
objects containing both they keys and the values. To iterate over just the values, you can usemap.values()
, which is a collection ofInteger
in this case.看来您想要的是
map.subMap(startx, endx).values()
而不是map.subMap(startx, endx).entrySet()
。It seems like what you want is
map.subMap(startx, endx).values()
instead ofmap.subMap(startx, endx).entrySet()
.