Skip to content
Advertisement

Getting a map and collectors error in kotlin function

I am trying to convert this java function to kotlin.

JavaScript

I end up with the following:

JavaScript

However on the line

JavaScript

I get the following error:

JavaScript

Advertisement

Answer

You don’t need stream() in kotlin. The collections classes in kotlin provides all methods you need. (e.g. map, distinct, toMap). Here is the kotlin way to write your function:

JavaScript

I don’t know the nullability of your data so I just leaves them all nullable. If you know the nullability, you should try to make the code as exact as possible.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement