1
votes

I am still getting my head around Scala, so trying to figure out what is missing in below code. I am getting this error message when i try to instantiate genericserializer with anonymous type

Description Resource Path Location Type type mismatch; found : scala.reflect.Manifest[Object] required: scala.reflect.Manifest[FolderMgmtDAO.this.anoMoveType] Note: Object >: FolderMgmtDAO.this.anoMoveType, but trait Manifest is invariant in type T. You may wish to investigate a wildcard type such as _ >: FolderMgmtDAO.this.anoMoveType. (SLS 3.2.10) FolderMgmtDAO.scala /somucore/src/somu/core line 20 Scala Problem

Below is the code

object GenericSerializer
{
  def apply[T <:AnyRef:Manifest]() = new GenericSerializer[T]()
}

class GenericSerializer[T <:AnyRef:Manifest] extends IMongoSerializer[T] {} 

//Anonymous type creation and using GenericSerializer
    type anoMoveType = { def folderPath:String } 
        val szr = GenericSerializer[anoMoveType]
1

1 Answers

0
votes

Looks like it's not possible with manifests. You should use TypeTag instead. Like this:

import scala.reflect.runtime.universe._
object GenericSerializer
{
  def apply[T <:AnyRef]()(implicit tag: TypeTag[T]) = {}
}