D
D
Denis Kuznetsov2021-06-27 23:18:34
Java
Denis Kuznetsov, 2021-06-27 23:18:34

How to rewrite code from kotlin to java?

Please help me to rewrite this code in Java, I can still somehow get the usual code from Kotlin to Java, but I'm confused with lambdas

consumer.consume(Consumer { record -> println("Got key "
        + record.key()).toString() +
        " val " +
        record.value().toString() })


the consume method itself on kotlin
fun consume(recordConsumer: Consumer<ConsumerRecord<String, String>>) {
        thread {
            while (true) {
                val records = consumer.poll(Duration.ofSeconds(1))
                records.forEach{record -> recordConsumer.accept(record)}
            }
        }
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question