Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在scala中定义一个带有名称调用参数的匿名函数?
我尝试了以下方法:
val fun = (x: Boolean, y: =>Int) => if(x) y else 0
这适用于按值调用 y,但不适用于按名称调用。为什么?
可以这样做,但方式略有不同:将类型与参数分开声明:
val fun: (Boolean, => Int) => Int = (x, y) => if (x) y else 0