gpt4 book ai didi

java - 如何强制 Scala 中指令的执行顺序

转载 作者:行者123 更新时间:2023-12-01 11:25:36 24 4
gpt4 key购买 nike

我注意到,Scala 并不总是按顺序执行指令。例如,如果您有以下说明。

var a = command1.!
var b = command2.!

第二条指令可能会在第一条指令之前执行,因为它与该指令没有任何依赖性。所以,我的问题是,如何强制在第一条指令之后执行第二条指令。

最佳答案

回答问题“我如何编写 ProcessBuilder?”,文档说:

Two existing ProcessBuilder can be combined in the following ways:

They can be executed in parallel, with the output of the first being fed as input to the second, like Unix pipes. This is achieved with the #| method.

They can be executed in sequence, with the second starting as soon as the first ends. This is done by the ### method.

The execution of the second one can be conditioned by the return code (exit status) of the first, either only when it's zero, or only when it's not zero. The methods #&& and #|| accomplish these tasks.

关于java - 如何强制 Scala 中指令的执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30829572/

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