I understand in Scala that Int is implicitly converted to RichInt. Where in the source does that occur (I was browsing the Scala source, but I couldn't find it...)
Look at Predef.intWrapper(Int): RichInt
This is inherited by Predef
from LowPriorityImplicits
. Inherited implicits have lower priorities than non inherited ones.
Note that by browsing library source you don't really get to see the conversion. The best way to see it on small snippet is to compile it (or run it in the REPL) with the -Xprint:typer
option. This will show the conversion that is inserted by the typer to make the code compile when the types don't match:
$ scala -Xprint:typer
scala> 3.abs
[[syntax trees at end of typer]]// Scala source: <console>
// stuff removed
private[this] val res0: Int = scala.this.Predef.intWrapper(3).abs;
// more stuff removed
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With