diff --git a/_overviews/scala3-book/types-intersection.md b/_overviews/scala3-book/types-intersection.md index deb7e58b0a..9336b7dd68 100644 --- a/_overviews/scala3-book/types-intersection.md +++ b/_overviews/scala3-book/types-intersection.md @@ -7,12 +7,16 @@ num: 50 previous-page: types-generics next-page: types-union --- - +Scala 3 only Used on types, the `&` operator creates a so called _intersection type_. The type `A & B` represents values that are **both** of the type `A` and of the type `B` at the same time. For instance, the following example uses the intersection type `Resettable & Growable[String]`: +{% tabs intersection-reset-grow %} + +{% tab 'Scala 3 Only' %} + ```scala trait Resettable: def reset(): Unit @@ -25,6 +29,10 @@ def f(x: Resettable & Growable[String]): Unit = x.add("first") ``` +{% endtab %} + +{% endtabs %} + In the method `f` in this example, the parameter `x` is required to be *both* a `Resettable` and a `Growable[String]`. The _members_ of an intersection type `A & B` are all the members of `A` and all the members of `B`.