Hello, i have on question regarding optional parameters:
for example i have a method called
Copy code
fun foo(val a: Int = 0)
is it possible to have some conditional calling of "foo" like?
Copy code
val dummyBoolean = true
foo(if(dummyBoolean) 1 else <use default value>)
a
André Thiele
12/23/2021, 9:42 AM
couldn't you just call it inside if {} with 1 else call it without? keep it simple
r
Rene Win
12/23/2021, 10:22 AM
yes i could, but i have a method with multiple parameters and therefore it would be a mess to put the if outside the parameters.
current workaround for me is that i just pass the same value as the default.
a
André Thiele
12/23/2021, 1:39 PM
pretty cumbersome to keep up if the declaration site changes or?