Fixed ListMap overload resolution ambiguity for kotlin

This commit is contained in:
Auxilor
2023-02-27 17:00:15 +00:00
parent af486580c1
commit 323a4aefef

View File

@@ -2,6 +2,27 @@
package com.willfp.eco.core.map
/**
* Required to avoid type ambiguity.
*
* @see ListMap
*/
@Suppress("RedundantOverride")
class MutableListMap<K : Any, V : Any> : ListMap<K, V>() {
/**
* Override with enforced MutableList type.
*/
override fun get(key: K?): MutableList<V> =
super.get(key)
/**
* Override with enforced MutableList type.
*/
override fun getOrDefault(key: K, defaultValue: MutableList<V>?): MutableList<V> {
return super.getOrDefault(key, defaultValue)
}
}
/**
* @see DefaultMap
*/
@@ -12,7 +33,7 @@ fun <K : Any, V : Any> defaultMap(defaultValue: V) =
* @see ListMap
*/
fun <K : Any, V : Any> listMap() =
ListMap<K, V>()
MutableListMap<K, V>()
/**
* @see DefaultMap.createNestedMap
@@ -24,4 +45,4 @@ fun <K : Any, K1 : Any, V : Any> nestedMap() =
* @see DefaultMap.createNestedListMap
*/
fun <K : Any, K1 : Any, V : Any> nestedListMap() =
DefaultMap.createNestedListMap<K, K1, V>()
DefaultMap<K, MutableListMap<K1, V>>(MutableListMap())