Florian Baierl
Florian Baierl

Reputation: 2481

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);
}

Upvotes: 1

Views: 189

Answers (1)

Florian Baierl
Florian Baierl

Reputation: 2481

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

Upvotes: 3

Related Questions