具有多个参数的scala隐式方法 [英] scala implicit method with multiple arguments
本文介绍了具有多个参数的scala隐式方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
In a comment for SIP-13 Martin Odersky implied that it is possible to create an implicit method with multiple arguments. According to my experiences, implicit methods always have exactly one argument and I cannot imagine how an implicit method with multiple arguments can be used. Can someone give some use case and explanation?
推荐答案
例如,如果您需要函数类型的隐式参数:
For example if you need an implicit parameter of a function type:
implicit def foo(x: Int, y: Int) = y * x
def bar(x: Int, y: Int)(implicit f: (Int, Int) => Int) = f(x,y)
scala> bar(3,4)
res3: Int = 12
这篇关于具有多个参数的scala隐式方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文