If I instantiate the following object:
object X : AbstractMap<Int, Int>() {
override val entries: Set<Map.Entry<Int, Int>> = object : AbstractSet<Map.Entry<Int, Int>>() {
override val size = 0
override fun iterator() = emptySet<Map.Entry<Int, Int>>().iterator()
}
}
then everything works fine.
However, if I omit the explicit type specification, like this:
object X : AbstractMap<Int, Int>() {
override val entries = object : AbstractSet<Map.Entry<Int, Int>>() {
override val size = 0
override fun iterator() = emptySet<Map.Entry<Int, Int>>().iterator()
}
}
then everything still compiles just fine, but at runtime I get this error:
java.lang.AbstractMethodError: Receiver class X does not define or inherit an implementation of the resolved method 'abstract java.util.Set getEntries()' of abstract class kotlin.collections.AbstractMap.
at kotlin.collections.AbstractMap.entrySet(AbstractMap.kt:21)
Playground
I was surprised to see this because this error is documented as:
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.
But in my case this error
has occurred without any change in the class.