Search code examples
javascalascala-java-interop

Calling a `scala.Function1[_root_.scala.Predef.String, scala.Any]` from within Java


I am currently working on a Java project that has to use another project written in Scala. My question is a very simple one: How can I call a scala.Function1[_root_.scala.Predef.String, scala.Any] from within my Java application?

The method I need to call is this:

var onMessageCb : scala.Function1[_root_.scala.Predef.String, scala.Any] = { /* compiled code */ }

This is how I am trying to call this function (in Java):

public void onMessage(String message) {
  onMessageCb(message);
}

Solution

  • I found the solution. It works when calling it like this: onMessageCb().apply(message);.