Converting "Callable<T>" Java method to Kotlin

Viewed 6781

I'm trying to convert a Java method:

private <T> Callable<T> createCallable(final Callable<T> task) {
    return () -> {
        try {
            return task.call();
        } catch (Exception e) {
            handle(e);
            throw e;
        }
    };
}

from the following Java file ExceptionHandlingAsyncTaskExecutor.java into Kotlin.

The code gets converted automatically using IntelliJ IDEA into:

private fun <T> createCallable(task: Callable<T>): Callable<T> {
    return {
        try {
            return task.call()
        } catch (e: Exception) {
            handle(e)
            throw e
        }
    }
}

which is not correct. But I have to idea what the correct implementation for this should be. Any ideas?

2 Answers
Related