I know I could just omit the parameter but then I ...
# getting-started
p
I know I could just omit the parameter but then I would have to do:
Copy code
if (s == null) foo() else foo(s)
h
Not sure default value helps you here, within
foo
you could
Copy code
fun foo(input: String?)  {
    val s = input ?: "default"
}
Or maybe do both
Copy code
fun foo(input: String? = "default")  {
    val s = input ?: "default"
}
a
Copy code
fun foo(input: String? = "hello"): String {
            return input ?: "default"
        }

        assert(foo() == "hello")
        assert(foo(null) == "default")
        assert(foo("bar") == "bar")
This illustrates the behaviour you can expect
if you provide the same value as parameter default and null elvis fallback, you get the desired behaviour, as described in OP
that is,
Copy code
fun foo(input: String? = "default"): String {
    return input ?: "default"
}

assert(foo() == "default")
assert(foo(null) == "default")
assert(foo("bar") == "bar")
p
thanks, that's pretty cumbersome tbh