Hello, i have on question regarding optional param...
# android
r
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
couldn't you just call it inside if {} with 1 else call it without? keep it simple
r
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
pretty cumbersome to keep up if the declaration site changes or?