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
how to fix problem but dont use this solution
def p2(a: Int, b: Int): Unit ={
implicit val bb = b
p1(a)
}
b
def p2(a: Int, b: Int): Unit ={
p1(a)(b)
}
b
as implicit in the signature of p2
def p2(a: Int)(implicit b: Int): Unit ={
p1(a)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.