I'm new to writing code in Scala. I'm trying to iterate over a java Map with custom objects as key value pairs. Specifically I'm trying to go over the Map of TopicPartitions and OffSetMetadata Map when committing offsets to Kafka.
Here is the code that i have written
override def onComplete(map: util.Map[TopicPartition, OffsetAndMetadata], e: Exception): Unit = {
val sb = new StringBuffer()
map.forEach((partition:TopicPartition ,offsets : OffsetAndMetadata) => {
sb.append(partition.topic()+","+partition.partition()+","+offsets.offset()+"\n")
})
However I get a compilation error saying
error: type mismatch; found : (org.apache.kafka.common.TopicPartition, org.apache.kafka.clients.consumer.OffsetAndMetadata) => StringBuffer [ERROR] required: java.util.function.BiConsumer[_ >: org.apache.kafka.common.TopicPartition, _ >: org.apache.kafka.clients.consumer.OffsetAndMetadata] [ERROR] map.forEach((partition:TopicPartition ,offsets : OffsetAndMetadata) => { [ERROR] ^
It indicates the => operator while pointing the error, any help is appreciated.