0

我收到此编译消息:

推断类型参数 [sdo.core.domain.Field[_ >: 2 with java.util.UUID <: java.lang.Comparable[ >: 1 with java.util.UUID <: java.lang.Object] with java. io.Serializable]] 不符合方法 :: 的类型参数界限 [B>: sdo.core.domain.Field[ >: String with org.scala_tools.time.Imports.DateTime <: java.lang.Comparable[ _ >: java.lang.String with org.joda.time.ReadableInstant <: java.lang.Object] with java.io.Serializable]] [error] override def fieldList = this.id :: this.create :: this .name :: this.description :: 无

我想要的是一个列表Field[_],或者任何与Field[_]. 我怎么做?

这是有问题的代码:

class Work( initialId :EntityUuidIdField, 
    initialName :NameField, 
    initialDescription :TextField) extends Entity{

    val id = initialId
    val name = initialName
    val description :Field[String]= initialDescription
    val create = new DateTimeField()
    val begun = new DateTimeField()
    val inProgress = new DateTimeField()
    val done = new DateTimeField()
    val subjectiveWellBeing = new SubjectiveWellBeingField()
    val size = new WorkSizeField()

    override def fieldList = this.id :: this.create ::  this.name :: this.description       :: Nil

    }

以及类型的定义:

class DateTimeField extends Field[DateTime] {

class EntityUuidIdField( val id :UUID) extends EntityIdField[UUID]( id) {

class EntityIdField[T]( id :T) extends Field[T] {

class NameField extends Field[String] {

class Field[T] extends Signal[T] {
4

1 回答 1

1

看起来不喜欢这三种类型的交集;我还没有尝试过-Yinfer-debug。

但是 List(x,y,z) 是可以的。

scala> trait X extends Comparable[X] with Serializable
defined trait X

scala> trait Y extends Comparable[Y] with Serializable
defined trait Y

scala> case class Foo[+A](a: A)
defined class Foo

scala> val x: Foo[X] = null
x: Foo[X] = null

scala>  val y: Foo[Y] = null
y: Foo[Y] = null

scala> val s : Foo[String] = null
s: Foo[String] = null

scala> s :: Nil
res0: List[Foo[String]] = List(null)

scala> y :: s :: Nil
res1: List[Foo[Comparable[_ >: String with Y <: java.io.Serializable] with java.io.Serializable]] = List(null, null)

scala> x :: y :: s :: Nil
<console>:15: error: inferred type arguments [Foo[Comparable[_ >: _2 with X <: java.io.Serializable] with java.io.Serializable]] do not conform to method ::'s type parameter bounds [B >: Foo[Comparable[_ >: String with Y <: java.io.Serializable] with java.io.Serializable]]
              x :: y :: s :: Nil

scala> val u: Foo[java.util.UUID] = null
u: Foo[java.util.UUID] = null

scala> x :: y :: u :: Nil
<console>:15: error: inferred type arguments [Foo[Comparable[_ >: _4 with X <: java.io.Serializable] with java.io.Serializable]] do not conform to method ::'s type parameter bounds [B >: Foo[Comparable[_ >: java.util.UUID with Y <: java.io.Serializable] with java.io.Serializable]]
              x :: y :: u :: Nil
                ^

scala> val a: Foo[AnyRef] = null
a: Foo[AnyRef] = null

scala> x :: y :: a :: Nil
res5: List[Foo[AnyRef]] = List(null, null, null)

scala> trait Z extends Comparable[Z] with Serializable
defined trait Z

scala> val z: Foo[Z] = null
z: Foo[Z] = null

scala> x :: y :: z :: Nil
<console>:16: error: inferred type arguments [Foo[Serializable with Comparable[_ >: _6 with X <: Serializable]]] do not conform to method ::'s type parameter bounds [B >: Foo[Serializable with Comparable[_ >: Z with Y <: Serializable]]]
              x :: y :: z :: Nil
                ^

scala> List(x,y,z,s,u)
res7: List[Foo[Comparable[_ >: java.util.UUID with String with Z with Y with X <: java.io.Serializable] with java.io.Serializable]] = List(null, null, null, null, null)
于 2012-10-01T03:40:43.230 回答