Why does this not compile?
class test
{
constructor() {
var a = Date().day
this(a)
}
constructor(a:Int) {
}
}
error is: Expression 'this' of type 'test' cannot be invoked as a function. The function 'invoke()' is not found.
The suggested fix is to add this:
private operator fun invoke(i: Int) {}
Why?
First, both of these constructors are secondary constructors. A primary constructor is one which is located outside of the body of the class.
Second, as described in the documentation, the correct syntax to call another constructor is as follows: