File tree Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Expand file tree Collapse file tree 2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -20,16 +20,16 @@ def f(x: Resettable & Growable[String]) = {
20
20
21
21
The value ` x ` is required to be _ both_ a ` Resettable ` and a
22
22
` Growable[String] ` . Intersection types ` A & B ` replace compound types
23
- ` A with B ` in Scala 2 (for the moment, ` A with B ` is still allowed, but
24
- it will be deprecated and removed in the future).
25
-
26
- Unlike ` with ` types, ` & ` is _ commutative_ : ` A & B ` is the same type as
27
- ` B & A ` .
23
+ ` A with B ` in Scala 2. For the moment, ` A with B ` is still allowed, but
24
+ its usage as a type (as opposed to in a ` new ` or ` extends ` clause) will be deprecated and removed in the future.
28
25
29
26
The members of an intersection type ` A & B ` are all the members of ` A `
30
27
and all the members of ` B ` . For instance ` Resettable & Growable[String] `
31
28
has member methods ` reset ` and ` add ` .
32
29
30
+ ` & ` is _ commutative_ : ` A & B ` is the same type as ` B & A ` , in that sense that the two types
31
+ have the same values and are subtypes of each other.
32
+
33
33
If a member appears in both ` A ` and ` B ` , its type in ` A & B ` is the
34
34
intersection of its type in ` A ` and its type in ` B ` . For instance, assume the definitions:
35
35
Original file line number Diff line number Diff line change @@ -22,3 +22,22 @@ object intersection {
22
22
def g : C [A | B ] = f
23
23
def h : C [A ] & C [B ] = g
24
24
}
25
+ object Test {
26
+
27
+ trait A {
28
+ def f : Any
29
+ }
30
+ trait B extends A {
31
+ override def f : Int = 1
32
+ }
33
+ trait C extends A {
34
+ def f : Any = " "
35
+ }
36
+
37
+ val bc : B with C = new C with B {}
38
+
39
+ def fooAB = (??? : A with B ).f
40
+ def fooAB1 : Int = fooAB
41
+ def fooBA = (??? : B with A ).f
42
+ def fooBA1 : Int = fooBA
43
+ }
You can’t perform that action at this time.
0 commit comments