Created
December 10, 2012 16:27
-
-
Save anoopelias/4251633 to your computer and use it in GitHub Desktop.
Implicit conversion in scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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