y
03/04/2024, 7:45 PMMyClass
to return MyClass?
that is, a constructor that can fail in ways that don't involve throwing exceptions?
as a trivial example, a class NonZeroInt(n: Int)
that returns null if constructed with n = 0
.
(I'm aware that I can do this with a companion object
)ephemient
03/04/2024, 7:56 PMreturn null
would have to not go through a Java-compatible constructor patternephemient
03/04/2024, 7:56 PMephemient
03/04/2024, 7:57 PMoperator fun Companion.invoke()
, which you mentioned)y
03/04/2024, 8:43 PM