Signature method considerations

Typical solution in Kotlin is to discriminate by the function name. And use factory functions instead of constructors:


class Foo private constructor(length: Int, height: Int) {
    companion object {
        fun withLength(length: Int) = Foo(length, 0)
        fun withHeight(height: Int) = Foo(0, height)
    }
}
3 Likes