The boring, correct answer is no, you canโt, but in fact you can, with experimental synthesis of one abstract method (SAM) in 2.11.
First you need to define your own SAM type with a default value for the apply method parameter:
trait Func { def apply(name: String = "joe"): Boolean }
Now you can use the function conventions to define Func (note that for this step you need to run REPL with -Xexperimental ):
val f: Func = { (name: String) => name == "joe" }
Or simply:
val f: Func = _ == "joe"
And then the usual stuff:
scala> f("joe") res0: Boolean = true scala> f("eoj") res1: Boolean = false
And pointling:
scala> f() res2: Boolean = true
This is not the syntax you are asking for, and there is no promises that it will ever leave experimental status, and even if it does, the default arguments may not be supported, but I still think it's pretty neat, it works now .
source share