Consider the following Scala code:
package scala_java
object MyScala {
def setFunc(func: Int => String) {
func(10)
}
}
Now in Ja
You have to manually instantiate a Function1
in Java. Something like:
final Function1 f = new Function1() {
public int $tag() {
return Function1$class.$tag(this);
}
public Function1 compose(Function1 f) {
return Function1$class.compose(this, f);
}
public String apply(Integer someInt) {
return myFunc(someInt);
}
};
MyScala.setFunc(f);
This is taken from Daniel Spiewak’s “Interop Between Java and Scala” article.