Janar
10/11/2018, 6:00 AMfun foo(s: String = "") = "hello $s"
fun bar(a: String?) {
foo(a ?: "")
}
In the above code is there a way for us to use the default value for the parameter in case a
is null, instead of repeating the default value in bar
?
This way, we don’t rely on what the default value of foo
is within bar
spand
10/11/2018, 6:02 AMfun foo(s: String? = null) = "hello ${s ?: ""}"
Janar
10/11/2018, 8:09 AMfoo
and bar
couldn’t be coupled like this.spand
10/11/2018, 8:13 AMfun foo(s: String = "") = "hello $s"
fun bar(a: String?) {
if (a != null) foo(a) else foo()
}