I am trying to call the following Java method from Kotlin:
KStream<K, V>[] branch(final Predicate<? super K, ? super V>... predicates);
This method is part of the Kafka Streams API.
The way I tried to call it, following the Kotlin docs, was by defining an extension method:
fun <K, V> KStream<K, V>.kbranch(vararg predicates: (K, V) -> Boolean):
Array<KStream<K, V>> = this.branch(*predicates)
The problem is that it doesn't compile. I get the following error:
Type mismatch: inferred type is Array<out (K, V) -> Boolean>
but Array<(out) Predicate<in K!, in V!>!>! was expected
The similar KStream#filter
method, which accepts a single Predicate
as an argument, can be called without any issue when passing a Kotlin lambda with the same signature of (K, V) -> Boolean
.
Any ideas? I have seen this similar question, but something here seems subtly different and I can't pinpoint it.