0

I am working on a project which contains both Scala and Java code. I have a Scala method defined as :

var responseListeners: List[(Int) => Unit]

  def addResponseListener(onResponse: Int => Unit) {
    responseListeners ::= onResponse
  }

And this method is called in Scala as:

addResponseListener(id => processors(id).wakeup())

Now I have some Java code in which I have access to the processors array, but how do I call the addResponseListener(onResponse: Int => Unit) from Java?

0

1 Answer 1

2

Use AbstractFunction1 from scala.runtime:

AbstractFunction1<scala.lang.Int, Void> f = (i) -> doWorkWith(i);

In the event that doWorkWith does not return void you'll need to return null; from the lambda:

i -> {
  doWorkWith(i);
  return null;
}

See also:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.