cedric
02/25/2016, 9:33 PMvmironov
02/25/2016, 9:34 PMcedric
02/25/2016, 9:34 PMorNull
voddan
02/25/2016, 9:34 PMvoddan
02/25/2016, 9:35 PMInteger.parseInt
to Kotlin (that's the only way)voddan
02/27/2016, 7:15 PMclone
collections:
mapOf(1 to 2) //?
setOf(1) //?
listOf(1).toList() //ok
// two of them!
arrayOf(1).copyOf()
arrayOf(1).clone()
DataClass(1).copy()
voddan
02/27/2016, 7:18 PMHashMap(mapOf(1 to 2))
HashSet(setOf(1))
ArrayList(listOf(1))
but it is only for mutable collectionskonsoletyper
02/27/2016, 8:18 PMvoddan
02/27/2016, 10:09 PMtoMap()
voddan
02/27/2016, 10:09 PMIterable<Pair<, >>
, which would be very inefficientvoddan
02/27/2016, 10:15 PM<K, V> Iterable<Map.Entry<K, V>>.toMap(): Map<K, V>
and
<K, V> Map<K, V>.toMap(): Map<K, V>
voddan
02/27/2016, 10:17 PMclone
function for every container (extension function?)michaelrocks
02/27/2016, 10:23 PMHashMap(map)
voddan
02/27/2016, 10:28 PMMap
voddan
02/27/2016, 10:28 PMorangy
voddan
02/28/2016, 7:05 AMkonsoletyper
02/28/2016, 7:28 AM.toList().toMap()
should work fine. I agree, it's slightly less efficient comparing to direct copying of a map, but not "very inefficient". Benchmarks are welcomevoddan
02/28/2016, 7:54 AMvoddan
02/28/2016, 7:55 AMkonsoletyper
02/28/2016, 8:02 AMmap.toList().toMap()
after HashMap
and see the difference. Don't forget HotSpot needs some time to warm up.voddan
02/28/2016, 8:14 AMtolist_tomap: 1000 rounds 818361095 ns, 818361 per round
time_hashmap: 1000 rounds 508941933 ns, 508941 per round
tolist_tomap_2: 1000 rounds 369167544 ns, 369167 per round
time_hashmap_2: 1000 rounds 183737713 ns, 183737 per round
voddan
02/28/2016, 8:14 AMvoddan
02/28/2016, 8:14 AMvoddan
02/28/2016, 8:15 AMvoddan
02/28/2016, 8:24 AMclone
method exists on all java collections, but to use it from cotlin you have to go under the interfaces Map
or MutableMap
konsoletyper
02/28/2016, 8:27 AMvoddan
02/28/2016, 8:29 AMkonsoletyper
02/28/2016, 8:33 AMvoddan
02/28/2016, 8:35 AM