In Scala, can you make an anonymous function have a default argument?
问题 This works: scala> def test(name: String = "joe"): Boolean = true test: (name: String)Boolean I expected this to work in the same way: scala> val test: String => Boolean = { (name: String = "joe") => true } <console>:1: error: ')' expected but '=' found. 回答1: The boring, correct answer is no, you can't, but actually you kind of can, with the experimental single abstract method (SAM) synthesis in 2.11. First you need to define your own SAM type with the default value for the apply method's