https://kotlinlang.org logo
#announcements
Title
# announcements
l

Luis Munoz

06/28/2019, 7:40 PM
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

Shawn

06/28/2019, 7:42 PM
You should just be able to pass in a lambda from the Java side
or method reference if applciable
l

Luis Munoz

06/28/2019, 8:02 PM
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

Shawn

06/28/2019, 8:08 PM
what’s the signature on the Kotlin side?
l

Luis Munoz

06/28/2019, 8:08 PM
shown four lines up, first code block is java calling site, and second is kotlin signature
s

Shawn

06/28/2019, 8:09 PM
oh my bad
2 Views