Scala, currying and overloading

后端 未结 3 1904
Happy的楠姐
Happy的楠姐 2020-12-06 00:41

Say you have the following:

foo(x: String)(y: Int): Int
foo(x: String)(y: Double): Int

Scala does not allow such expression. As far as I ca

3条回答
  •  伪装坚强ぢ
    2020-12-06 01:13

    A simple workaround is to use an anonymous object:

    def foo(x: String) = new {
      def apply(y: Int): Int
      def apply(y: Double): Int
    }
    

提交回复
热议问题