Title: maxBy((Map.Entry<K, V>) -> R): Map.Entry<K, V>?' is deprecated. Use maxByOrNull instead
Tags: android;kotlin
Question: 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&gt;) -&gt; R): Map.Entry<K, V&gt;?' 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

Comment: 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

Comment: try this https://stackoverflow.com/questions/31712046/kotlin-unresolved-reference-in-intellij



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2020:00:12/22/20', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><kotlin>', 'Title': "maxBy((Map.Entry<K, V>) -> R): Map.Entry<K, V>?' is deprecated. Use maxByOrNull instead", 'ViewCount': 1369, 'id': 65411983, 'user_AboutMe': '', 'user_AccountId': 445732.0, 'user_DisplayName': 'ir2pid', 'user_Reputation': 4966.0, 'user_Views': 763.0, 'user_id': 838355.0}}