为什么以下代码失败:
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))
显然,第一个无法编译,因为在这个位置调用整数文字是无效的。请参阅this question当您可以在 Scala 中省略括号和点时,获得进一步的解释。
关于scalatest 调用不带括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32566515/