scala - How to get rid of : class type required but T found -
how solve 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]]() 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 error :
[error] container.scala:23: class type required t found [error] override def get[t]: seq[t] = entities.get(classof[t]).map(_.toseq).getorelse(seq.empty).asinstanceof[seq[t]]
t
not class type, type parameter. request classtag
:
import scala.reflect._ override def get[t](implicit ct: classtag[t]): seq[t] = entities.get(ct.runtimeclass) .map(_.toseq) .getorelse(seq.empty) .asinstanceof[seq[t]]
but brings problem; not override!
so have modify base of operations class declare get
follows:
def get[t: classtag]: seq[t]
scala
No comments:
Post a Comment