Created
October 12, 2020 12:36
-
-
Save ch8n/e0d67da8e884aafd783bbb5b1e548f0b to your computer and use it in GitHub Desktop.
map resolved by linked hashmap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun <K, V> mapOf(vararg pairs: Pair<K, V>): Map<K, V> | |
= if (pairs.size > 0){ | |
pairs.toMap(LinkedHashMap(mapCapacity(pairs.size))) | |
}else{ | |
emptyMap() | |
} | |
// Linked HashMap signature | |
class LinkedHashMap<K, V> : MutableMap<K, V> | |
// since MutableMap<K, V> has Map as parent class | |
// Casting it to map make it immutable* (read-only) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment