Skip to content

Instantly share code, notes, and snippets.

@anoopelias
Created December 10, 2012 16:27
Show Gist options
  • Save anoopelias/4251633 to your computer and use it in GitHub Desktop.
Save anoopelias/4251633 to your computer and use it in GitHub Desktop.
Implicit conversion in scala
package concept
object ImpicitConversion {
class Val {
def value = 10
}
/* Implicit Conversion begins */
class PrintVal(v : Val) {
def printValue = {
println("Value is : " + v.value)
}
}
implicit def toPrint(v:Val) = new PrintVal(v)
/* Implicit Conversion ends */
val v = new Val()
v.value //> res0: Int = 10
v.printValue //> Value is : 10
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment