2

I'm trying to use maxBy in kotlin but I get a deprecated warning to replace it with maxByOrNull.

val max = response.maxBy { it.value.size }

maxBy((Map.Entry<K, V>) -> R): Map.Entry<K, V>?' is deprecated. Use maxByOrNull instead.

The autofix in android studio does it like below

val max = maxByOrNull({ it.value.size })

But this doesn't compile with error

Unresolved reference: maxByOrNull

What is the proper implementation as response.maxByOrNull { it.value.size } also doesn't work

ir2pid
  • 5,604
  • 12
  • 63
  • 107
  • try this https://stackoverflow.com/questions/31712046/kotlin-unresolved-reference-in-intellij – Ryuzaki L Dec 22 '20 at 16:10
  • You need to call it on ``response``, same as your original ``maxBy`` version. If it's still not working (highlighted in red) put the text cursor on it, hit alt+enter and pick the import option – cactustictacs Dec 22 '20 at 19:39

0 Answers0