Scala中的行继续符 [英] Line continuation character in Scala
本文介绍了Scala中的行继续符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想像这样拆分以下Scala代码行:
I want to split the following Scala code line like this:
ConditionParser.parseSingleCondition("field=*value1*").description
must equalTo("field should contain value1")
但是行继续符是哪个?
推荐答案
将其括在括号中:
(ConditionParser.parseSingleCondition("field=*value1*").description
must equalTo("field should contain value1"))
Scala没有换行符"-总是在以下情况下推断分号:
Scala does not have a "line continuation character" - it infers a semicolon always when:
- 表达式可以结束
- 以下(非空白)行不以可以启动语句的令牌开头
- 之前没有找到未关闭的
(
或[
- An expression can end
- The following (not whitespace) line begins not with a token that can start a statement
- There are no unclosed
(
or[
found before
因此,要延迟"分号推断,可以将方法调用或点放在行尾,或将点放在下一行的开头:
Thus, to "delay" semicolon inference one can place a method call or the dot at the end of the line or place the dot at the beginning of the following line:
ConditionParser.
parseSingleCondition("field=*value1*").
description must equalTo("field should contain value1")
a +
b +
c
List(1,2,3)
.map(_+1)
这篇关于Scala中的行继续符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文