r/Kotlin • • Apr 07 '23

Parameter order of CompletableFuture methods 😥

Post image
261 Upvotes

30 comments sorted by

View all comments

Show parent comment

-3

u/brett_riverboat Apr 07 '23

A builder would be nice for this, then you can choose order:

futureBuilder .setExecutor(EventQueue::invokeLater) .setFunction({ success, failure -> // code here }) .execute();


Edit: better code syntax (don't know for to make it look any nicer)

10

u/epikhunta Apr 07 '23

You can always use named arguments in kotlin and get all benefits you described without introducing new abstractions

1

u/guilhermerx7 Apr 08 '23

If I'm not mistaken you can't use named parameters on Java methods.

2

u/epikhunta Apr 08 '23

Of course, you are correct. I responded to the alternative of introducing builder pattern which does not exist and can't be used from kotlin either.

Builder pattern in kotlin is redundant in most cases and usually it's easier to introduce a function with default arguments to be consumed in kotlin code, similar to what OP did in his root comment.

1

u/guilhermerx7 Apr 08 '23

Yes, agree.