Scala 冲突的继承方法名称

发布于 2024-12-15 01:00:28 字数 506 浏览 3 评论 0原文

我正在尝试编写一些代码来测试数据库模型。测试框架和数据库框架都使用“===”运算符,并且优先考虑测试框架。我如何明确地使用一种方法或另一种方法?

示例:

import org.scalatest.FunSuite

class TestDBModels extends FunSuite{
  test("Test DoublePropertyEntry with a few new values") {
    Schemas.doubleProperties.deleteWhere(p => (p.id === p.id)))
  }
}

错误:

type mismatch;
found   : Option[String]
required: org.squeryl.dsl.ast.LogicalBoolean
Schemas.doubleProperties.deleteWhere(p => (p.===(p.id, p.id)))

I am trying to write some code to test a database model. Both the test framework and the database framework use the "===" operator, and the test framework's is being given preference. How can I explicitly use one method or the other?

Example:

import org.scalatest.FunSuite

class TestDBModels extends FunSuite{
  test("Test DoublePropertyEntry with a few new values") {
    Schemas.doubleProperties.deleteWhere(p => (p.id === p.id)))
  }
}

Error:

type mismatch;
found   : Option[String]
required: org.squeryl.dsl.ast.LogicalBoolean
Schemas.doubleProperties.deleteWhere(p => (p.===(p.id, p.id)))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

廻憶裏菂餘溫 2024-12-22 01:00:28

您有多种选择。第一个也是最简单的方法是使用显式方法调用而不是隐式转换。例如,要显式使用 scalatest ===:

Schemas.doubleProperties.deleteWhere(p => (convertToEqualizer(p.id) === p.id)))

如果这太长,您可以缩短名称:

def toEq(left: Any) = convertToEqualizer(left: Any)
Schemas.doubleProperties.deleteWhere(p => (toEq(p.id) === p.id)))

convertToEqualizer 是 scalatest 的隐式转换方法。另一种选择是将 ConvertToEqualizer 重写为非隐式方法:

override def convertToEqualizer(left: Any) = new Equalizer(left)

这会阻止这种特定隐式转换的发生。请参阅 Assertions 对象的 scalatest 文档关于 scalatest-users 的相同问题邮件列表

You have a number of options. The first and easiest is to use an explicit method call instead of the implicit conversion. For example, to explicitly use the scalatest ===:

Schemas.doubleProperties.deleteWhere(p => (convertToEqualizer(p.id) === p.id)))

If this is too long, you could shorten the name:

def toEq(left: Any) = convertToEqualizer(left: Any)
Schemas.doubleProperties.deleteWhere(p => (toEq(p.id) === p.id)))

convertToEqualizer is the implicit conversion method for scalatest. One other option is to override convertToEqualizer as a non-implicit method:

override def convertToEqualizer(left: Any) = new Equalizer(left)

This stops this particular implicit conversion happening. See the scalatest documentation for Assertions object and the same question on the scalatest-users mailing list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文