y
08/14/2023, 5:07 AMMap
? alternatively, is there a sorted map type other than TreeMap
(because that one is a Java thing and gives me platform types)Joffrey
08/14/2023, 7:13 AMy
08/14/2023, 7:13 AMy
08/14/2023, 7:14 AMJoffrey
08/14/2023, 7:16 AMy
08/14/2023, 7:18 AMhorse_badorties
08/14/2023, 8:38 AMyourMap.toSortedMap().forEach(...)
?ephemient
08/14/2023, 1:01 PM.entries.sortedBy { it.key }
to give you what you wantKlitos Kyriacou
08/15/2023, 11:27 AMTreeMap
was a Kotlin type that you can't do because it's a Java type?y
08/15/2023, 11:29 AMephemient
08/15/2023, 12:20 PMJoffrey
08/15/2023, 12:46 PMTreeMap
is actually most useful when you want to read or remove subtrees based on the sorting of the keys, like "give me the subtree of all keys below 42". If you just want sorted iteration, it's most likely better to just iterate on the sorted entries in the places where you need that.Klitos Kyriacou
08/15/2023, 12:55 PMTreeMap
seems to behave as if Kotlin knows its nullability requirements, so the following doesn't compile:
java.util.TreeMap<String, String>().put(null as String?, "")
On the other hand, various other Java types that also require an argument to be non-null, do in fact compile:
java.io.FileOutputStream(null as java.io.File?)
y
08/15/2023, 12:58 PM