Can someone explain me implicit conversions in Scala?

Posted by Oscar Reyes on Stack Overflow See other posts from Stack Overflow or by Oscar Reyes
Published on 2010-05-18T22:08:07Z Indexed on 2010/05/19 1:10 UTC
Read the original article Hit count: 318

And more specifically how does the BigInt works for convert int to BigInt?

In the source code it reads:

...
implicit def int2bigInt(i: Int): BigInt = apply(i)
...

How is this code invoked?

I can understand how this other sample: "Date literals" works.

In.

val christmas = 24 Dec 2010  

Defined by:

implicit def dateLiterals(date: Int) = new {
  import java.util.Date  
  def Dec(year: Int) = new Date(year, 11, date)
}

When int get's passed the message Dec with an int as parameter, the system looks for another method that can handle the request, in this case Dec(year:Int)

Q1. Am I right in my understanding of Date literals?

Q2. How does it apply to BigInt?

Thanks

© Stack Overflow or respective owner

Related posts about scala

Related posts about implicit-conversion