This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can I pass concrete values into a Data Collection  RSS feed

 
Geane Norm
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
this is a very beginner question I stumbled upon today and I am slightly puzzled. I have a method with the following signature:

where ConsumerRecords is a Kafka API class as explained here: https://kafka.apache.org/090/javadoc/index.html?org/apache/kafka/clients/consumer/KafkaConsumer.html

In my main method, I would like to call method1 and pass concrete values (in my case a topic and key-value pairs). Is that possible? How do I do it?

Thanks,

I.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Geane Norm wrote:In my main method, I would like to call method1 and pass concrete values (in my case a topic and key-value pairs). Is that possible?

No, because the method is specified to take only one value - a Map.

How do I do it?

Re-write the method (or write a new one) that takes two values - one of each type defined in the Map, eg:
  method2(String topic, ConsumerRecords<String, String> records) { ...

However, the latter one looks like a collection itself, so if you just want to supply a single "record", you'll have to work out the type of a single record for a ConsumerRecords object.

HIH

Winston
 
Connor Van Elswyk
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the String (key) is what your referring to as a "topic" then update your data structure from a Map to a Multimap so you can have multiple values to a single key.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!