0

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
  • 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. Commented Jun 21, 2015 at 19:13

1 Answer 1

4

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.