Created
August 28, 2018 03:49
-
-
Save dbtsai/5e036aac666f337770488e7983a9197c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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