Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of : class type required but T found

Tags:

How to solve this compilation error :

trait Container {   def getInts() : Seq[Int]   def getStrings() : Seq[String]    def put[T](t: T)   def get[T] : Seq[T] }  class MutableContainer extends Container {   val entities = new mutable.HashMap[Class[_], mutable.Set[Any]]() with mutable.MultiMap[Class[_], Any]    override def getStrings(): Seq[String] = entities.get(classOf[String]).map(_.toSeq).getOrElse(Seq.empty).asInstanceOf[Seq[String]] //strings   override def getInts(): Seq[Int] = entities.get(classOf[Int]).map(_.toSeq).getOrElse(Seq.empty).asInstanceOf[Seq[Int]]    override def get[T]: Seq[T] = entities.get(classOf[T]).map(_.toSeq).getOrElse(Seq.empty).asInstanceOf[Seq[T]]   override def put[T](t: T): Unit = entities.addBinding(t.getClass, t) } 

Here is the error :

[error] Container.scala:23: class type required but T found [error]       override def get[T]: Seq[T] = entities.get(classOf[T]).map(_.toSeq).getOrElse(Seq.empty).asInstanceOf[Seq[T]]