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
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.
16
16
{% endtab %}
17
17
{% tab 'Scala 3' %}
18
-
In Scala 3, an implicit conversion from type `S` to type `T` is defined by a [given instance]({% link _tour/implicit-parameters.md %}) which has type `scala.Conversion[S, T]`, or by an implicit method which can be eta-expanded to the function type `S => T`.
18
+
In Scala 3, an implicit conversion from type `S` to type `T` is defined by a [given instance]({% link _tour/implicit-parameters.md %}) which has type `scala.Conversion[S, T]`. For compatibility with Scala 2, they can also be defined by an implicit method (read more in the Scala2 tab).
19
19
{% endtab %}
20
20
{% endtabs %}
21
21
@@ -24,14 +24,14 @@ Implicit conversions are applied in two situations:
24
24
1. If an expression `e` is of type `S`, and `S` does not conform to the expression's expected type `T`.
25
25
2. In a selection `e.m` with `e` of type `S`, if the selector `m` does not denote a member of `S`.
26
26
27
-
In the first case, a conversion `c` is searched for which is applicable to `e` and whose result type conforms to `T`.
27
+
In the first case, a conversion `c` is searched for, which is applicable to `e` and whose result type conforms to `T`.
28
28
29
29
An example is to pass a `scala.Int`, e.g. `x`, to a method that expects `scala.Long`. In this case, the implicit conversion `Int.int2long(x)` is inserted.
30
30
31
31
32
-
In the second case, a conversion `c` is searched for which is applicable to `e` and whose result contains a member named `m`.
32
+
In the second case, a conversion `c` is searched for, which is applicable to `e` and whose result contains a member named `m`.
33
33
34
-
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.
34
+
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.)
35
35
36
36
**Beware the power of implicit conversions:**
37
37
@@ -48,14 +48,14 @@ No warning is emitted when the conversion is applied by the compiler.
48
48
{% endtab %}
49
49
{% tab 'Scala 3' %}
50
50
Because implicit conversions can have pitfalls if used indiscriminately the compiler warns in two situations:
51
-
- when compiling the implicit conversion definition (for Scala 2 style conversions).
51
+
- when compiling a Scala 2 style implicit conversion definition.
52
52
- at the call site where a given instance of `scala.Conversion` is inserted as a conversion.
53
53
54
54
To turn off the warnings take either of these actions:
55
55
56
56
- Import `scala.language.implicitConversions` into the scope of:
0 commit comments