Skip to content

Commit 28d87d0

Browse files
Sporarumbishabosha
andauthored
Apply code review suggestions for file structural-types.md
Co-authored-by: Jamie Thompson <[email protected]>
1 parent 70e7811 commit 28d87d0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/_docs/reference/changed-features/structural-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Using `Selectable` and [Java reflection](https://www.oracle.com/technical-resour
9393

9494
> Before resorting to structural calls with Java reflection one should consider alternatives. For instance, sometimes a more a modular _and_ efficient architecture can be obtained using [type classes](https://docs.scala-lang.org/scala3/book/types-type-classes.html).
9595
96-
For example, we would like to provide behavior for both [`FileInputStream`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/FileInputStream.html#%3Cinit%3E(java.io.File)) and [`Channel`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/channels/Channel.html) classes by caling their `close` method, however, these classes are unrelated, i.e. have no common supertype with a `close` method. Therefore, below we define a structural type `Closeable` that defines a `close` method.
96+
For example, we would like to provide behavior for both [`FileInputStream`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/io/FileInputStream.html#%3Cinit%3E(java.io.File)) and [`Channel`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/channels/Channel.html) classes by calling their `close` method, however, these classes are unrelated, i.e. have no common supertype with a `close` method. Therefore, below we define a structural type `Closeable` that defines a `close` method.
9797

9898
```scala
9999
type Closeable = { def close(): Unit }
@@ -119,7 +119,7 @@ def autoClose(f: Closeable)(op: Closeable => Unit): Unit =
119119
The call `f.close()` requires `Closeable` to extend `Selectable` to identify and call the `close` method in the receiver `f`. A universal implicit conversion to `Selectable` is enabled by an import
120120
of `reflectiveSelectable` shown above, based on [Java reflection](https://www.oracle.com/technical-resources/articles/java/javareflection.html). What happens "under the hood" is then the following:
121121

122-
- The implicit wraps `f` in an instance of `scala.reflect.Selectable` (which is a subtype of `Selectable`).
122+
- The implicit conversion wraps `f` in an instance of `scala.reflect.Selectable` (which is a subtype of `Selectable`).
123123

124124
- The compiler then transforms the `close` call on the wrapped `f`
125125
to an `applyDynamic` call. The end result is:

0 commit comments

Comments
 (0)