blob: 8791d61e6ac0ee6b5d28379799fa15e6f261a6aa (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
class X(val elem: Int) {
def foo(y: String): Int = y.length + elem
}
object X {
implicit class BarDeco(x: X) {
def bar: String = "!"
}
}
object Implicits {
implicit val impl: X = new X(0)
implicit def conv(x: Int): X = new X(x)
class Xdecorator(x: X) extends Object {
def foo(cond: Boolean): Int = if (cond) x.foo("abc") else 0
}
implicit def XDecorator(x: X): Xdecorator = new Xdecorator(x)
val a: Object = "abc"
val b: Any = "abc"
def foo(x: Int)(implicit y: X): Int = {
println(y)
x
}
val y: Int = foo(1)
val z: X = 3
val c: Int = y.elem
val d: Int = z.foo("abc")
//import X.BarDeco
println(z.bar)
val e: Int = z.foo(true)
}
|