A class for implicit values that can serve as implicit conversions. The implicit resolution algorithm will act as if there existed the additional implicit definition:
def $implicitConversion[T, U](x: T)(c: Conversion[T, U]): U = c(x)
However, the presence of this definition would slow down implicit search since its outermost type matches any pair of types. Therefore, implicit search contains a special case in Implicits#discardForView which emulates the conversion in a more efficient way.
Note that this is a SAM class - function literals are automatically converted to the Conversion values.
Also note that in bootstrapped dotty, Predef.<:< should inherit from Conversion. This would cut the number of special cases in discardForView from two to one.
The Conversion class can also be used to convert explicitly, using the convert extension method.
| Supertypes |
|---|
Convert value x of type T to type U
Composes two instances of Function1 in a new Function1, with this function applied first.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | a new function |
| Inherited from | Function1 |
Composes two instances of Function1 in a new Function1, with this function applied last.
| Type parameters |
|
|---|---|
| Value parameters |
|
| Returns | a new function |
| Inherited from | Function1 |
Returns a string representation of the object.
The default representation is platform dependent.
| Returns | a string representation of the object. |
|---|---|
| Definition Classes | Function1 -> Any |
| Inherited from | Function1 |
x.convert converts a value x of type T to type U
© 2002-2022 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://scala-lang.org/api/3.2.0/scala/Conversion.html