Scalatest 调用不带括号

Scalatest call be without parenthesis

为什么下面的代码会失败:

session.getGameId should be 10 

有这个错误

';' expected but integer literal found.

然而这个并没有失败

session.getGameId should be(10)

是否与apply方法的调用方式有关

session.getGameId should be 10

表示

(session.getGameId).should(be).(10)

session.getGameId should be(10)

表示

(session.getGameId).should(be(10))

显然,第一个不能编译,因为在这个位置调用整数文字是无效的。当您可以在 Scala 中省略括号和点时,请参阅 this question 以获取更多说明。