I am currently writing a generic function to execute Dispatch async requests, but I can't access generic type in Dispatch handler:
private def execQuery[MessageType](query : Req, errorMsg : String)
{
Http(query OK as.String).either
.onSuccess
{
case Left(error) => println(errorMsg)
case Right(json) => println( new MessageType(json) ) // error here
}
}
I have an error on new MessageType : "Cannot resolve symbol MessageType" in "new MessageType(json)". Can you help me ?
Thank you in advance
Victor
EDIT : I have found an other interesting way here http://www.brentsowers.com/2011/11/writing-generic-functions-that-take.html. You have to use the manifest feature :
class DynamicTestClass() {
def output() {
println("Hello from a dynamically sent class")
}
}
def testFunc[T : Manifest]() : T = {
manifest[T].erasure.newInstance().asInstanceOf[T]
}
val dynamicTestClassInstance = testFunc[DynamicTestClass]()
dynamicTestClassInstance.output()
It seems to work !