You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/reference/enums/adts.md
+4-6Lines changed: 4 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,15 +48,13 @@ scala> Option.None
48
48
valres2: t2.Option[Nothing] =None
49
49
```
50
50
51
-
Note that the type of the expressions above is always `Option`. That
52
-
is, the implementation case classes are not visible in the result
53
-
types of their `apply` methods. This is a subtle difference with
54
-
respect to normal case classes. The classes making up the cases do
55
-
exist, and can be unveiled by constructing them directly with a `new`.
51
+
Note that the type of the expressions above is always `Option`. Generally, the type of a enum case constructor application will be widened to the underlying enum type, unless a more specific type is expected. This is a subtle difference with respect to normal case classes. The classes making up the cases do exist, and can be unveiled, either by constructing them directly with a `new`, or by explicitly providing an expected type.
56
52
57
53
```scala
58
54
scala>newOption.Some(2)
59
-
valres3: t2.Option.Some[Int] =Some(2)
55
+
valres3:Option.Some[Int] =Some(2)
56
+
scala>valx:Option.Some[Int] =Option.Some(3)
57
+
valres4:Option.Some[Int] =Some(3)
60
58
```
61
59
62
60
As all other enums, ADTs can define methods. For instance, here is `Option` again, with an
0 commit comments