范围限制
我很惊讶。为什么对 Range 类型的实现进行限制,其大小受 Int.MaxValue 限制? 谢谢。
i'm surprised. Why was made restriction of implementation to type Range, is whose the size limited by Int.MaxValue?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自
NumericRange
文档,From the
NumericRange
docs,在我看来,另一个答案是错误的。
它演示了您可以使用其他数字类型,但这并没有改变
Range
只能容纳2³1
元素的事实,就像 Scala/Java 中的所有其他集合一样。据我所知,这个设计决策背后没有真正的理由。拥有 64 位集合当然很好,并且对具有 64 位索引的数组的支持对于 Java 来说很常见,但很难将其集成到现有的语言/集合框架中。有人说 JVM 的对象总数被限制为 40 亿个,但我无法验证这一点。
In my opinion the other answer is just wrong.
It demonstrates that you can use other number types, but this doesn't change the fact that a
Range
can only hold2³¹
elements, like every other collection in Scala/Java.As far as I know there is no real rationale behind this design decision. Having 64-bit collections would be certainly nice and support for arrays with 64bit indices are common for Java, but it is hard to integrate that into the existing language/collection framework. Some people say that the JVM is limited to a total of 4 billion objects, but I couldn't verify that.