In my setup, I'm trying to have an interface Table that inherits from Map (because it will mostly be used as a wrapper around the map). Two classes inherit from Table - local and global. The global one will have a mutable map, and the local one will have a map of only local entries.
// entries
sealed class Entry {
class EntryLocal : Entry
class EntryGlobal : Entry
}
interface Table : Map<String, Entry> {
fun getRecursive(key: String): Entry?
}
class GlobalTable(val map:MutableMap<String, Entry>) : Table, Map<String, Entry> by map {
override fun getRecursive(key: String) = this[key]
...
}
class LocalTable(
private val parent: Table,
val map: Map<String, EntryLocal>
) : Table, Map<String, EntryLocal> { // gives error
override fun getRecursive(key: String): Entry? = map[key] ?: parent.getRecursive(key)
}
I get the following error:
Type parameter V of 'Map' has inconsistent values: Entry, EntryVar
Why is that? Doesn't Map<String, EntryLocal> inherit from Map<String, Entry>?