The Kotlin documentation says that if all of the p...
# announcements
a
The Kotlin documentation says that if all of the primary constructor parameters for a class have default values, on the JVM, Kotlin will create an additional parameterless constructor. So I was surprised that this doesn't work:
Copy code
class BadTest(val name: String? = null)
val badTestCreator: () -> BadTest = ::BadTest
But that this does work:
Copy code
class GoodTest(val name: String? = null) {
    constructor(): this(name = null)
}
val goodTestCreator: () -> GoodTest = ::GoodTest
Shouldn't there be a no-arg constructor for
BadTest
that would satisfy the
() -> BadTest
type?
z
I think it generates one in the bytecode, but the type of the constructor "function" still includes all the parameters, which is why you can't pass a reference to it as a nullary function.