File tree 1 file changed +9
-1
lines changed
1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,16 @@ num: 50
7
7
previous-page : types-generics
8
8
next-page : types-union
9
9
---
10
-
10
+ < span class = " tag tag-inline " >Scala 3 only</ span >
11
11
12
12
Used on types, the ` & ` operator creates a so called _ intersection type_ .
13
13
The type ` A & B ` represents values that are ** both** of the type ` A ` and of the type ` B ` at the same time.
14
14
For instance, the following example uses the intersection type ` Resettable & Growable[String] ` :
15
15
16
+ {% tabs intersection-reset-grow %}
17
+
18
+ {% tab 'Scala 3 Only' %}
19
+
16
20
``` scala
17
21
trait Resettable :
18
22
def reset (): Unit
@@ -25,6 +29,10 @@ def f(x: Resettable & Growable[String]): Unit =
25
29
x.add(" first" )
26
30
```
27
31
32
+ {% endtab %}
33
+
34
+ {% endtabs %}
35
+
28
36
In the method ` f ` in this example, the parameter ` x ` is required to be * both* a ` Resettable ` and a ` Growable[String] ` .
29
37
30
38
The _ members_ of an intersection type ` A & B ` are all the members of ` A ` and all the members of ` B ` .
You can’t perform that action at this time.
0 commit comments