yes it works! but still feel confused about that. If I marked as nullable,then the default value should be
null
, why I have to add the default value explicitly. 😅
v
Vampire
11/30/2022, 5:55 PM
No, if it is nullable it means someone invoking it can specify
null
, but the invoker still has to decide what he wants to give. If you want the parameter to be optional in terms of being able to not specify it, you have to define a default value which can be
null
but also any other valid value.
✅ 1
Vampire
11/30/2022, 5:56 PM
Actually it might also be better to not use a nullable type here, but instead use an empty map as default value.
k
Klitos Kyriacou
11/30/2022, 5:59 PM
Nullability and existence of a parameter are two separate concepts.
Consider an overload:
Copy code
fun foo(name: String, info: May<Int, Map<String, Any>>?) { ... }
fun foo(name: String) { ... }
Now you can call
foo("bar", null)
and
foo("bar")
and those are different things. The first is a null parameter, the second is no parameter.
🙌 1
v
Vampire
11/30/2022, 6:42 PM
Same with the default argument though, so what does that add except for more verbosity?