File tree 1 file changed +6
-1
lines changed
1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -7,12 +7,15 @@ 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 reset-grow class=tabs-scala-version %}
17
+ {% tab 'Scala 3 Only' %}
18
+
16
19
``` scala
17
20
trait Resettable :
18
21
def reset (): Unit
@@ -24,6 +27,8 @@ def f(x: Resettable & Growable[String]): Unit =
24
27
x.reset()
25
28
x.add(" first" )
26
29
```
30
+ {% endtab %}
31
+ {% endtabs %}
27
32
28
33
In the method ` f ` in this example, the parameter ` x ` is required to be * both* a ` Resettable ` and a ` Growable[String] ` .
29
34
You can’t perform that action at this time.
0 commit comments