Skip to content

Instantly share code, notes, and snippets.

@dbtsai
Created August 28, 2018 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbtsai/5e036aac666f337770488e7983a9197c to your computer and use it in GitHub Desktop.
Save dbtsai/5e036aac666f337770488e7983a9197c to your computer and use it in GitHub Desktop.
object ObjWithMethod {
def runClosure(body: () => Boolean): Boolean = {
println("In runClosure")
val method = Class.forName("ObjWithMethod")
.getDeclaredMethod("calledByRefection", classOf[() => Boolean])
method.invoke(null, body).asInstanceOf[Boolean]
}
def calledByRefection(body: => Boolean): Boolean = {
println("In calledByRefection")
body
}
}
object ReflectionWithMethodInObj {
def main(args: Array[String]): Unit = {
val body: () => Boolean = () => {
println("In body")
true
}
ObjWithMethod.runClosure { () =>
println("In Body")
true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment