Java 8 Stream 之 short-circuiting

结贴是美德 2017-08-07 11:28:20
An intermediate operation is short-circuiting if, when presented with infinite input, it may produce a finite stream as a result. A terminal operation is short-circuiting if, when presented with infinite input, it may terminate in finite time. Having a short-circuiting operation in the pipeline is a necessary, but not sufficient, condition for the processing of an infinite stream to terminate normally in finite time.


求大神解答一下,充要条件是啥?
...全文
378 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
结贴是美德 2017-08-08
  • 打赏
  • 举报
回复
哪位大神给讲一下呀,冲要条件是啥。。。 我想到一点就是在短路操作之前,不能有那种必须出结果才能走到下一步的操作,否则根本到不了短路逻辑就依然无限循环了。
soton_dolphin 2017-08-07
  • 打赏
  • 举报
回复
就是说如果由无限的流,转到有限的流,不管是中间操作还是终结操作都叫做短路。 由无限流转成有限流的中间操作有 limit(). 由无限流转成有限流的终结操作有 findAny(), findFirst, anyMatch(). 如果想终结无限流操作,用短路是必须的,但并不足够,可能还需要其他的流操作

62,625

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧