kirillrakhman
11/21/2016, 12:12 PMFoo(val bar: Int = 2). Now I have a factory method that delegates to the constructor and it should be possible to either pass a value for bar or just use the default value. I can write
fun createFoo(bar: Int? = null) = Foo(bar ?: 2)
but that duplicates the default value which is pointless.
I could also write
fun createFoo(bar: Int? = null) = if (bar != null) Foo(bar) else Foo()
but that doesn't scale if I have more than one default parameter.
I could also just omit the default value in the constructor and put it in the factory method but it seems to be the wrong place (or is it?).
What's your opinion?