简体   繁体   English

Java SortedMap-TreeMap键超出范围

[英]Java SortedMap - TreeMap Key out of Range

I'm working on a project where I use a TreeMap as chronological index. 我正在一个项目中使用TreeMap作为时间索引。

SortedMap<Long, String> expiryIndex = new TreeMap<>();
Long now = System.currentTimeMillis();
expiryIndex.put(now, null);

The aim is to later be able to create TailSet of "older" items without having to iterate. 目的是以后无需迭代就可以创建“较旧”项目的TailSet。 However, I'm not getting this far because already at put I get an exception: 但是,我没有走这么远,因为我已经得出了一个例外:

SEVERE: Unhandled exception
java.lang.IllegalArgumentException: key out of range

I don't see what I could have done wrong here. 我看不到我在这里可能做错了什么。

As a matter of fact this was indeed my fault. 事实上,这确实是我的错。

I had a code block further down, where I sliced a tailset out of it. 我在后面有一个代码块,在其中切出了一个尾音。 Since these slices are value by reference, the put in the corresponding tailslice was out of bounds, although it was made into the full set. 由于这些切片是按参考值,因此放入完整的尾部切片的范围是超出范围的。 Hence Davidxxx's comment was basically the hint. 因此,Davidxxx的评论基本上是提示。

Still.. weird. 还是..怪异的。 Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM