Reputation: 25
I am not able to understand how scala converts Int to BigDecimal in scala.
val a : BigDecimal = 1
The above statement should have ideally thrown a compilation error , however it compiles fine. Could anyone please explain how does this happen in scala?
Upvotes: 1
Views: 157
Reputation: 3638
The answer to this question lies in the BigDecimal object which has an implicit method that converts Int to BigDecimal.
From the source code of scala
object BigDecimal extends scala.AnyRef with scala.Serializable {
// all other methods
implicit def int2bigDecimal(i : scala.Int) : scala.math.BigDecimal = { /* compiled code */ }
}
Please let me know if this answers your question.
Upvotes: 4