Scala 的未来版本可能会用作then关键字,如SIP-12中所述中所述。
编译器已经显示了警告:
\n\n\n\n\n不推荐使用 then 作为标识符。它可以在 scala 的未来版本中用作关键字。\n 然后,Word 在 scala 的未来版本中被保留为可能的关键字。不推荐使用 it\xe2\x80\x99s 作为标识符。参见 SIP-12。
\n
我正在使用 Mockito 并且出现了很多次then方法。
BDDMockito.then(entityService).should(Mockito.times(2)).findBy(any)\nRun Code Online (Sandbox Code Playgroud)\n\n有谁知道是否有替代方案可以替代它?
\n在 scala 中,将任何标识符括在反引号“`”中可以防止将其视为关键字。
BDDMockito.`then`(entityService).should(Mockito.times(2)).findBy(any)
Run Code Online (Sandbox Code Playgroud)
这最常用于允许命名字段/变量/方法,但它也type应该适用。then有时它也用于将空格嵌入到标识符中。
case class Bar(`class`: Int, `type`: String) {
def `class with type`: String = s"${`class`}_${`type`}"
}
Bar(42, "skidoo").`class with type` == "42_skidoo"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
394 次 |
| 最近记录: |