So say I have some simple data class like this:
data class Transaction(
val time: Long,
val sender: String,
val data: ByteArray
)
And in Kotlin I have the following method defined:
fun handleTransaction(transactionGetter: ()->Transaction) {
// do something
}
How do I go about calling this method from Java?
I've tried trying to make a java lambda but can't figure it out. It is telling me that the parameter is supposed to be a Function0<Transaction> but I am not too sure how to define that.
Okay so, I figured out I can do this:
handleTransaction(new Function0<Transaction>() {
@Override
public Transaction invoke() {
// handle getting transaction
}
});
Is that really the right way to do it? It is quite ugly.
() -> createTransaction()just like a Java Supplier<Transaction>.