Skip to content

Instantly share code, notes, and snippets.

@andypetrella
Created March 3, 2013 13:45
Show Gist options
  • Save andypetrella/5076140 to your computer and use it in GitHub Desktop.
Save andypetrella/5076140 to your computer and use it in GitHub Desktop.
DuckTyping.scala
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