Due Manifest is deprecated (Since Scala 2.10.0) this is the updated answer -
import scala.reflect.ClassTag
import scala.reflect._
object WorkUnitController extends Controller {
def updateObject[T: ClassTag](toUpdate: T, body: JsonObject){
val source = gson.fromJson(body, classTag[T].runtimeClass)
???
}
}
You should use ClassTag
instead of ClassManifest
and .runtimeClass
instead of .erasure
Original answer -
Yes, you can do that using manifests:
object WorkUnitController extends Controller {
def updateObject[T: ClassManifest](toUpdate: T, body: JsonObject){
val source = gson.fromJson(body, classManifest[T].erasure);
...
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…