相关疑难解决方法(0)

仅当要转换的函数具有至少两个参数时,才将函数隐式转换为二阶函数

我有隐式转换和高阶函数的问题.似乎只有转换函数至少有两个参数,函数到二阶函数的隐式转换才有效.

作品:

implicit def conv(foo: Integer => String): String => String = null
Run Code Online (Sandbox Code Playgroud)

不起作用:

implicit def conv(foo: Integer => String): String => String => String = null
Run Code Online (Sandbox Code Playgroud)

作品:

implicit def conv(foo: (Integer, Integer) => String): String => String => String = null
Run Code Online (Sandbox Code Playgroud)

完整的失败点示例:

{
    implicit def conv(foo: Integer => String): String => String = null

    def baadf00d(foo: Integer): String = null

    def deadbeef(foo: String => String) = null

    deadbeef(conv(baadf00d))

    deadbeef(baadf00d)
}

{
    implicit def conv(foo: Integer => String): String => …
Run Code Online (Sandbox Code Playgroud)

scala implicit-conversion higher-order-functions

7
推荐指数
1
解决办法
434
查看次数