gpt4 book ai didi

java - 为什么 Spliterators.spliteratorUnknownSize() 不是后期绑定(bind)?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:23:49 26 4
gpt4 key购买 nike

我今天阅读了有关拆分器的内容,并使用 Spliterators.spliteratorUnknownSize(iterator(), Spliterator.NONNULL) 实现了一个。根据 spliteratorUnknownSize() 的文档

The [resulting] spliterator is not late-binding

作为拆分器的新手,我想知道为什么会这样。如果我确保 iterator() 是后期绑定(bind)的,那么生成的拆分器也应该是,不是吗? spliteratorUnknownSize() 只是创建一个尚未绑定(bind)到元素源的 IteratorSpliterator

即,我很想了解为什么生成的拆分器不是后期绑定(bind)的。谢谢。

最佳答案

根据javadocs :

"A Spliterator that does not report IMMUTABLE or CONCURRENT is expected to have a documented policy concerning: when the Spliterator binds to the element source; and detection of structural interference of the element source detected after binding. A late-binding Spliterator binds to the source of elements at the point of first traversal, first split, or first query for estimated size, rather than at the time the Spliterator is created. A Spliterator that is not late-binding binds to the source of elements at the point of construction or first invocation of any method. Modifications made to the source prior to binding are reflected when the Spliterator is traversed. After binding a Spliterator should, on a best-effort basis, throw ConcurrentModificationException if structural interference is detected. ..."

因此,如果您仔分割析,后期绑定(bind)非后期绑定(bind) 的真正区别在于何时开始检测结构干扰。

Spliterator 包装任意 迭代器不能保证检测到结构干扰。这取决于 Iterator 是如何实现的。即使对于检测(或减轻)结构干扰的 IteratorsSpliterator 也无法保证检测何时开始;即当“绑定(bind)”发生时。

简而言之,它不能保证真正的后期绑定(bind)语义。


If I ensure iterator() to be late-binding, the resulting Spliterator should also be, no?

javadocs 不保证这一点。

在实践中:它可能应该是,尽管它取决于 Spliterators 的实现。但是在 javadoc 中做出这样的声明可能会以有害的方式限制 future 版本的 Spliterators 类及其嵌套类的实现。


您可能不同意我的分析。然而,javadocs 的作者已经明确而有意地声明这些 Spliterator 不是后期绑定(bind)的。如果您认为他们对此有误,请针对 javadoc 提出错误报告。

关于java - 为什么 Spliterators.spliteratorUnknownSize() 不是后期绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54138679/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com