Created
September 24, 2012 21:30
-
-
Save ckirkendall/3778515 to your computer and use it in GitHub Desktop.
Showing how implicits can demonstrate contra and co variance with out all the type noise.
This file contains hidden or 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 example | |
class Widget(val description : String) | |
class CoolWidget extends Widget("cool widget") | |
class Sprocket(val description : String) | |
object Sprocket { | |
def printDescription(s : Sprocket){ | |
println(s.description) | |
} | |
} | |
class CoolSprocket(override val description : String) extends Sprocket(description) | |
object Main extends App { | |
implicit def widgetToCoolSprocket(w: Widget) : CoolSprocket ={ | |
return new CoolSprocket(w.description); | |
} | |
var myCoolWidget = new CoolWidget(); | |
Sprocket.printDescription(myCoolWidget); | |
println(Lists.max(List(1,3,2))) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment