RosettaCodeData/Task/Send-an-unknown-method-call/Scala/send-an-unknown-method-call.scala
2023-07-01 13:44:08 -04:00

12 lines
398 B
Scala

class Example {
def foo(x: Int): Int = 42 + x
}
object Main extends App {
val example = new Example
val meth = example.getClass.getMethod("foo", classOf[Int])
assert(meth.invoke(example, 5.asInstanceOf[AnyRef]) == 47.asInstanceOf[AnyRef], "Not confirm expectation.")
println(s"Successfully completed without errors. [total ${scala.compat.Platform.currentTime - executionStart} ms]")
}