Line continuation character in Scala

前端 未结 1 1514
太阳男子
太阳男子 2020-12-17 08:34

I want to split the following Scala code line like this:

ConditionParser.parseSingleCondition(\"field=*value1*\").description 
  must equalTo(\"field should          


        
相关标签:
1条回答
  • 2020-12-17 09:34

    Wrap it in parentheses:

    (ConditionParser.parseSingleCondition("field=*value1*").description 
      must equalTo("field should contain value1"))
    

    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)
    
    0 讨论(0)
提交回复
热议问题