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[ >: 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 :: Nil

私が欲しいのは のリスト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

3 つのタイプの交差が気に入らないようです。-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 に答える