I have a (seemingly) odd problem. It can be reproduced with just a few lines:
open class Parent(val map: HashMap<String, Any>) {
// constructor(unusedArgument: Int): this(hashMapOf())
}
class Child: Parent(hashMapOf(Pair("key", "value")))
It compiles and works as expected as long as I keep Parent's secondary constructor commented out.
Once I put it back in, this lint error pops up where the Child's parent constuctor is called:
Error: None of the following functions can be called with the arguments supplied:
public constructor Parent(map: HashMap) defined in Parent
public constructor Parent(unusedArgument: Int) defined in Parent
The error goes away if any of these is true:
- I specify variance as
HashMap<String, out Any>, - My secondary constructor is empty,
mapis declared asMapinstead ofHashMap(which I don't do because for my purposes I need it to implementSerializable).
To be honest, it doesn't make much sense to me. Why does it happen only if I add non-empty secondary constructor to the parent class? What does it have to do with anything? And how exactly do these "fixes" fix it?
Thanks.