1

I have to write scheduler that callbacks a function after processing. I can register the class name and method name as strings and have to callback it in future.

How can I call a function with class name and method name in Scala.

1 Answer 1

2

Same with java, use reflect.

package tst

class A {
  def fun(a:String) = print(a)
}

object B extends App {
  val classA = Class.forName("tst.A")
  val method = classA.getDeclaredMethod("fun", classOf[String])
  method.invoke(classA.newInstance(), "hello world")
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.