I have a Kotlin function that looks like this
calculateFib(upto: Int, fn: (Int) -> Unit): Unit
which I can call from Kotlin like this:
fib.calculateFib(8, ::println)
I’m trying to call this from Java and hoped I could do this:
fib.calculateFib(10, System.out::println);
but I get a ‘Found method reference expected Function1’ error
So I implement Function1 but the invoke
method is pretty ugly
@Override
public Unit invoke(Object o) {
System.out.println(o);
return null;
}
Is there a better way?
Thanks