10000 enhance implicit conversions section · scalacenter/docs.scala-lang@f2c90e3 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2c90e3

Browse files
committed
enhance implicit conversions section
1 parent b679db2 commit f2c90e3

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

_tour/implicit-conversions.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ previous-page: implicit-parameters
1010
redirect_from: "/tutorials/tour/implicit-conversions.html"
1111
---
1212

13+
Implicit conversions are a powerful Scala feature that enable two common use cases:
14+
- allow users to supply an argument of one type, as if it were another type, to avoid boilerplate.
15+
- to provide additional members to closed classes (replaced by [extension methods][exts] in Scala 3).
16+
17+
### Detailed Explanation
1318
{% tabs implicit-conversion-defn class=tabs-scala-version %}
1419
{% tab 'Scala 2' %}
1520
In Scala 2, an implicit conversion from type `S` to type `T` is defined by an [implicit value]({% link _tour/implicit-parameters.md %}) which has function type `S => T`, or by an implicit method convertible to a value of that type.
@@ -33,7 +38,11 @@ In the second case, a conversion `c` is searched for, which is applicable to `e`
3338

3439
An example is to compare two strings `"foo" < "bar"`. In this case, `String` has no member `<`, so the implicit conversion `Predef.augmentString("foo") < "bar"` is inserted. (`scala.Predef` is automatically imported into all Scala programs.)
3540

36-
**Beware the power of implicit conversions:**
41+
### How are implicit conversions selected?
42+
43+
See this [Scala FAQ Answer](https://docs.scala-lang.org/tutorials/FAQ/index.html#where-does-scala-look-for-implicits).
44+
45+
### Beware the power of implicit conversions
3746

3847
{% tabs implicit-conversion-warning class=tabs-scala-version %}
3948
{% tab 'Scala 2' %}
@@ -59,3 +68,5 @@ To turn off the warnings take either of these actions:
5968
- Invoke the compiler with `-language:implicitConversions`
6069
{% endtab %}
6170
{% endtabs %}
71+
72+
[exts]: {% link _overviews/scala3-book/ca-extension-methods.md %}

0 commit comments

Comments
 (0)
0