Created
March 3, 2013 13:45
-
-
Save andypetrella/5076140 to your computer and use it in GitHub Desktop.
DuckTyping.scala
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 test | |
object Template { | |
case object A { | |
def apply(i:Int) = "A " + i | |
} | |
case object B { | |
def apply() = "B" | |
} | |
case object C { | |
def apply(i:Int) = "C " + i | |
} | |
def test(i:Int, o:{def apply(i:Int):String}) = o(i) | |
def test(o:{def apply():String}) = o() | |
println(test(1, A)) | |
println(test(1, C)) | |
println(test(B)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment