class A {
def m (key:Int): Unit = {
println(s"Calling the method m in Class A with key value $key")
}
}
implicit class B (a: A) {
println("implicit transform Class A to Class B")
def f (str: String) {
println(s"Calling the method f in implicit Class B with str value $str")
}
}
scala> val test = new A
test: A = A@695336b2
scala> test m 3
Calling the method m in Class A with key value 3
scala> test f "hello"
implicit transform Class A to Class B
Calling the method f in implicit Class B with str value hello
Implicit conversions
最新推荐文章于 2024-08-21 14:41:58 发布