[英]Could not find implicit value for parameter in scala
def p1(c: Int)(implicit b: Int): Unit = {
println(c + b)
}
def p2(a: Int, b: Int): Unit ={
p1(a)
}
p2(5, 6) //result = 11
error: could not find implicit value for parameter b: Int
错误:找不到参数b的隐式值:Int
how to fix problem but dont use this solution 如何解决问题,但不要使用此解决方案
def p2(a: Int, b: Int): Unit ={
implicit val bb = b
p1(a)
}
b
b
def p2(a: Int, b: Int): Unit ={
p1(a)(b)
}
b
as implicit in the signature of p2
b
标记为隐含在p2
的签名中 def p2(a: Int)(implicit b: Int): Unit ={
p1(a)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.