0
votes

The error can be reproduced in the console with the following code.

case class SomeClass(name: String)

abstract class Factory() {
  protected def create[U](name: String) : U
}

class SomeFactory extends Factory() {
  override def create[SomeClass](name: String) = SomeClass(name)
} 

<console>:11: error: type mismatch;
found : SomeClass(in object $iw) required: SomeClass(in method create) override def create[SomeClass](name: String) = SomeClass(name)

1
It looks like you need the generic parameter to go on the Factory class? At the moment create needs to support any type specified by the client. - Lee

1 Answers

4
votes

Seems like this is what you're trying to achieve:

case class SomeClass(name: String)

abstract class Factory[U]() {
  protected def create(name: String) : U
}

class SomeFactory extends Factory[SomeClass] {
  def create(name: String) = SomeClass(name)
}

(I'm assuming you meant for SomeFactory to extend Factory)