I have a method like this:
def aMethod(param: String = "asdf") = {
...
}
If the method is called as follows, then param is given the default value “asdf”:
aMethod() ...
But what I would like, is that if the method is called with null, then the default value would also be applied:
aMethod(null) //inside the method, I can use `param` and it has the value "asdf".
Whats the best way to do this in Scala? I can think of pattern matching or a simple if statement.
Pattern matching
Option (implicitly)
Option (explicitly)
The last approach is actually the most idiomatic and readable once you get use to it.