I've come up with my own solution, which seems a bit cleaner than the one proposed by @david-soroko.
fun <T> Iterable<T>.javaForEach(consumer: Consumer<T>) = forEach(consumer)
The main point here is that the Iterable.forEach
takes a Consumer
, Kotlin's forEach
takes a lambda and explicitly passing the Consumer
resolves to the java forEach
.
And just changing forEach
to javaForEach
looks cleaner than always casting.