Skip to content
Advertisement

How to call Scala curry functions from Java with Generics

A Scala code has a retry mechanism which is based on currying function:

JavaScript

I want to call this code from Java (8), which use generics:

JavaScript

How should it be done?

Thanks.

Advertisement

Answer

For

JavaScript

try

JavaScript

Parameters from multiple parameter lists in Scala should be seen in Java as parameters of a single parameter list.

Scala and Java functions should be interchangeable (since Scala 2.12)

How to use Java lambdas in Scala (https://stackoverflow.com/a/47381315/5249621)

By-name parameters => T should be seen as no-arg functions () => T.

I assumed that Data implements TransactionWithResult and TransactionWithoutResult, so Data can be used where TransactionWithResult or TransactionWithoutResult is expected, otherwise the code should be fixed.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement