Created
January 18, 2022 18:11
-
-
Save Haaroon/ef6699a32f8a8423eb954c4ffed512ac to your computer and use it in GitHub Desktop.
type gist
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
sealed trait Callable[T] { | |
def call(): T | |
} | |
object Caller { | |
def call[C, A <: Callable[C]](callable: A): C = { | |
callable.call() | |
} | |
} | |
case class Duck(name: String) extends Callable[String] { | |
def call(): String = { | |
"quack" | |
} | |
} | |
val duck = Duck("Donald") | |
println(Caller.call[String, Duck](duck)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment