Hi, why calling `thenApply` like this is possible ...
# announcements
j
Hi, why calling
thenApply
like this is possible
Copy code
CompletableFuture.completedFuture("x").thenApply { it }
but second version with executor
Copy code
CompletableFuture.completedFuture("x").thenApply({ it }, Executors.newCachedThreadPool())
throws compilation error and I have to do something like this
Copy code
CompletableFuture.completedFuture("x").thenApply(java.util.Function<String, String> { it }, Executors.newCachedThreadPool())
l
just a guess, I haven’t tried myself, but try like this
Copy code
CompletableFuture.completedFuture(“x”).thenApplyAsync({ it }) { Executors.newCachedThreadPool() }
j
thenApply
does not receive two functions, just one and executor, so this is not correct
l
oh sorry, I used
thenApplyAsync
i see
m
I think it’s because the first argument is eligible for SAM -> lambda conversion. And Kotlin either wants all two arguments as lambdas or none of them.
l
and the second i{} s not a function is just a kotlin syntax sugar for the last parameter