scala case class with type parameter got confusing "type mismatch" compile time error

Viewed 92

I have case class ValueContainer with two operations, removeFirst fails with:

 type mismatch;
 found   : Option[T(in class ValueContainer)]
 required: Option[T(in method removeFirst)]
    def removeFirst[T]: RemovalOperationResult[T] = RemovalOperationResult(container.headOption, ValueContainer(container.drop(1)) )

Does anyone have an idea why it doesn't like to compile?

final case  class ValueContainer[+T](private val container: List[T])
{
  def addValue[A >:T] (value:A) : ValueContainer[A] = ValueContainer(value::container)
  def removeFirst[T]: RemovalOperationResult[T] = RemovalOperationResult(container.headOption, ValueContainer(container.drop(1)) )
}

final case class RemovalOperationResult[T](itemRemoved: Option[T], remainingValues: ValueContainer[T])
0 Answers
Related