Created
October 21, 2013 13:13
-
-
Save Arakaki/7083668 to your computer and use it in GitHub Desktop.
Duck Typing
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
object Main { | |
def main(args:Array[String]) { | |
//Duck typing | |
def quackTheDuck( quackable: {def quack:String }) = { | |
"What does a duck say? " + quackable.quack | |
} | |
class RealDuck { def quack = "Quack!" } | |
class ImposterDuck { def quack = "Qwaack!" } | |
quackTheDuck(new RealDuck) | |
quackTheDuck(new ImposterDuck) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment