Created
July 17, 2011 01:21
-
-
Save johnkpaul/1087002 to your computer and use it in GitHub Desktop.
Implicit conversions 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
class Mixin(value: Int){ | |
def myCrazyNameOperator(f: Int => Int) : Int = f(value) | |
} | |
implicit def toWTF(value: Int) = new Mixin(value); | |
def double(int: Int) = {2 * int} | |
def triple(int:Int) = {3 * int} |
I don't know if I can really give you a satisfying answer because I don't understand it completely myself. Apparently scala allows what are called implicit conversions that allow conversion methods that take type parameters that are implicitly called in such a way that it seems like I can add methods to any existing class. http://www.codecommit.com/blog/ruby/implicit-conversions-more-powerful-than-dynamic-typing
One day I will understand this better and be able to give a better explanation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
English, please.