mardi 25 août 2015

How to pass method to another method using Scala reflection?

Working with scala reflection i dived into a trouble with methods that receive another methods as argument. Suppose i have package lib like this:

package lib

object A {
   def reg(f: String => String) = ???
}

object B {
   def f(String) : String = ""
}

And i have external storage that contains full names of objects A and B. For instance:

val aPath = "lib.A"
val fPath = "lib.B.f"

When i execute invoke(aPath, fPath) method it using reflection must run such code:

lib.A.reg(lib.B.f)

How can i achive this with scala reflection ?





Aucun commentaire:

Enregistrer un commentaire