当伴生对象在类中时使用 .tupled 方法 [英] Using .tupled method when companion object is in class

查看:40
本文介绍了当伴生对象在类中时使用 .tupled 方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 Slick 迁移到 Slick 2,在 Slick 2 中,您打算在投影到案例类时使用 tupled 方法(如下所示 http://slick.typesafe.com/doc/2.0.0-RC1/migration.html)

I am in the process of migrating from Slick to Slick 2, and in Slick 2 you are meant to use the tupled method when projecting onto a case class (as shown here http://slick.typesafe.com/doc/2.0.0-RC1/migration.html)

问题是当 case 类有一个伴生对象时,即如果你有这样的东西

The problem is when the case class has a companion object, i.e. if you have something like this

case class Person(firstName:String, lastName:String) {

}

与伴生对象一起

object Person {
  def something = "rawr"
}

在同一范围内,tupled 方法不再有效,因为它试图在 object 上运行 tupled,而不是 tupled代码>案例类.

In the same scope, the tupled method no longer works, because its trying to run tupled on the object, instead of the case class.

有没有办法检索Personcase class而不是object,这样你就可以调用tupled正确吗?

Is there a way to retrieve the case class of Person rather than the object, so you can call tupled properly?

推荐答案

你也可以写

(Person.apply _).tupled

避免重复类型.

这篇关于当伴生对象在类中时使用 .tupled 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆