I'd like to do in Scala something I would do in Java like this:
public void recv(String from) {
recv(from, null);
}
public void recv(String from, Integer key) {
/* if key defined do some preliminary work */
/* do real work */
}
// case 1
recv("/x/y/z");
// case 2
recv("/x/y/z", 1);
In Scala I could do:
def recv(from: String,
key: Int = null.asInstanceOf[Int]) {
/* ... */
}
but it looks ugly. Or I could do:
def recv(from: String,
key: Option[Int] = None) {
/* ... */
}
but now call with key looks ugly:
// case 2
recv("/x/y/z", Some(1));
What's the proper Scala way? Thank you.