I've got the following models:
case class Questionnaire(List(Question[_])
case class Question[A](text: String, Answer[A])
case class Answer[A](value: A)
I'm trying to set all of the answers on a questionnaire depending on their type (answers can be of type String, Double or LocalDate):
val questionnaire = getMockQuestionnaireWithoutAnswers()
questionnaire.questions.map {
case x: Question[String] => //...default the answer.value to some random string
case x: Question[Double] => //...default the answer.value to some random double
case x: Question[LocalDate] => //...default the answer.value to some random date
}
But I'm getting the error:
non-variable type argument String in type pattern examplenamespace.Question[String] is unchecked since it is eliminated by erasure.
I don't want to wrap all of the types into classes like this:
case class StringQuestion(question: Question[String])
What is the best way to avoid this error?