def save(f: => Any)(run:Boolean) { if (run) { println("running f"); f } else println("not running f") }
me puede llamar con:
save("test")(true) -> running f
save("test")(false) -> not running f
save(throw new RuntimeException("boom!"))(false) -> not running f
save(throw new RuntimeException("boom!"))(true) -> running f and then exception thrown
Aquí está el curioso comportamiento con aplicación parcial:
save(throw new RuntimeException("boom!"))(_) -> (Boolean) => Unit = <function1> //as expected
save(throw new RuntimeException("boom!")) _ -> exception thrown
El bloque de código se evalúa inmediatamente sin pasarlo como una función. ¿Cuál es la diferencia entre las 2 afirmaciones anteriores?
Puede encontrar algunas explicaciones aquí: http://stackoverflow.com/questions/2363013/in-scala-why-cant-i-partially-apply-a-function-without-expllicitly-specifying-it –
En mi humilde opinión, esto es un error. –