Scala标签类型
问题描述:
使用:Scala 2.10.3Scala标签类型
尝试编译以下内容时出现错误。如果我删除案例类,那么它编译。
Anythoughts上的双从解决?
object DomainTypes {
type Tagged[T] = { type Tag = T }
trait DeviceIdTag
type DeviceId = Int with Tagged[DeviceIdTag]
implicit class TaggedInt(val data: Int) extends AnyVal {
def deviceId = {
require(data >= 1)
data.asInstanceOf[DeviceId]
}
}
}
case class DeviceIdHolder(odeviceId:DeviceId)
[错误]类型不匹配; [error] found:Double [error] required:AnyRef [error]注意:隐式存在于scala.Double => java.lang.Double中,但从Object继承的 [error]方法呈现不明确。这是为了避免 [错误]一个隐式的隐式将转换任何scala.Double到任何AnyRef。 [错误]您可能希望使用类型归属:
x: java.lang.Double
。 [错误]一个错误发现 [错误](编译:编译)编译失败 [错误]总时间:0秒,完成了2014年3月2日上午11时47分01秒
如果更换INT的随着字符串的编译,所以我不认为有任何结构错误的本质。
你使用的是什么版本的scala? – rapvelopment
已更新至版本。这可能与此有关:http://stackoverflow.com/questions/20094679/case-class-companion-object-generation-error-for-compound-type – bearrito
该消息在2.11下可能更有帮助。 –