y
02/02/2025, 9:14 AM: this(...)
, and just allowing any function which returns an instance of the class/object? in practice, I find this limitation of constructors makes them mostly useless, and so I'm forced to use companion objects or module-level free functionsephemient
02/02/2025, 11:50 AMy
02/02/2025, 11:53 AMrkechols
02/02/2025, 6:26 PMoperator fun invoke(...): MyClass
in the companion object works great. Doesn't have the limitations of a regular constructor, but it sure presents itself like a constructorShawn
02/02/2025, 6:54 PMthis()
right in the secondary constructor signature is very deliberate and was done to avoid a whole host of initialization bugs. This doesn't make secondary constructors useless; it helps minimize their misuse.y
02/02/2025, 7:01 PMoperator invoke
, because IDE support sometimes fails to jump to it, because it's operator overloading and especially because it's yet another competing Kotlin syntax for a class constructor.
if I'm going to add a companion object
"constructor", I prefer a descriptive name.