为Abstract类Scala Slick创建映射列类型

时间:2015-06-04 23:26:57

标签: scala slick slick-2.0

我正在尝试为我拥有的抽象案例类创建MappedCOlumnType

sealed abstract class Address(address: String)
implicit val addressToString = MappedColumnType.base[Address, String](
  addr => addr.address,
  addr => AddressUtil.address(addr)
)

但是我收到编译错误,说明:

value address is not a member of com.suredbits.core.protocol.Address
[error]  Note: implicit value addressToString is not applicable here because it comes after the application point and it lacks an explicit result type
[error]   {addr => addr.address } , { addr => AddressUtil.address(addr) }

当我明确地将address声明为案例类中的字段时。我觉得这对我来说可能是一个非常愚蠢的错误。为什么我的地址字段不可见?

1 个答案:

答案 0 :(得分:0)

示例中的address对构造函数是私有的。要使用getter将其公开,请将val添加到其前面,如下所示:

sealed abstract class Address(val address: String)

HTH。