If I have a kotlin class that takes a function as ...
# announcements
l
If I have a kotlin class that takes a function as an argument (a block). How do I initialize that class from java, link to documentation might suffice. I don't see that in https://kotlinlang.org/docs/reference/java-interop.html ?
s
You should just be able to pass in a lambda from the Java side
or method reference if applciable
l
return new SuspendingBatchingPublisherImpl<UnsubscribeEvent, UnsubscribeEventList>( subscriptionRabbitTemplate(), (list) -> new UnsubscribeEventList(list), (eventList) -> eventList.getEvents().size(), applicationProperties.getUnsubscribeMessages() );
not working for some reason
class SuspendingBatchingPublisherImpl<T, R>( private val rabbitTemplate: RabbitTemplate, private val eventBatchingProperties: EventBatchingProperties, private val batchFunction: (items: List<T>) -> R, private val batchLength: (R) -> Int 😞 CoroutineScope {
error is :
UnsubscribeEventList cannot be applied to lambda parameter
(list) -> new UnsubscribeEventList(list), highlights the second list
s
what’s the signature on the Kotlin side?
l
shown four lines up, first code block is java calling site, and second is kotlin signature
s
oh my bad