instantiate object with reflection using constructor arguments

Posted by justin on Stack Overflow See other posts from Stack Overflow or by justin
Published on 2009-10-29T01:11:19Z Indexed on 2012/09/20 15:38 UTC
Read the original article Hit count: 173

Filed under:
|

I'm trying to figure out how to instantiate a case class object with reflection. Is there any support for this? The closest I've come is looking at scala.reflect.Invocation, but this seems more for executing methods that are a part of an object.

case class MyClass(id:Long, name:String)

def instantiate[T](className:String)(args:Any*) : T = { //your code here }

Is close to the API I'm looking for.

Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about reflection

Related posts about scala