Created
August 3, 2017 15:51
-
-
Save knightpop/9ad231a6d4b621e7ebad3bc0115b4e5b to your computer and use it in GitHub Desktop.
This file contains 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
implicit val optionInt: Option[Int] = Some(1) | |
implicit val optionBoolean: Option[Boolean] = Some(true) | |
def getImplicitOptionInt(implicit oInt: Option[Int]): Int = oInt.get | |
def getImplicitOptionBoolean(implicit oBoolean: Option[Boolean]): Boolean = oBoolean.get | |
getImplicitOptionInt | |
getImplicitOptionBoolean | |
def getImplicitlyOptionA[A: Option]: A = implicitly[Option[A]].get | |
getImplicitlyOptionA[Int] | |
getImplicitlyOptionA[Boolean] | |
trait Parent { | |
def sayHello: String | |
} | |
trait Son extends Parent { | |
override def sayHello: String = "Hello! I'm Son!" | |
} | |
trait Daughter extends Parent { | |
override def sayHello: String = "Hello! I'm Daughter!" | |
} | |
def sayHello[A <: Parent](a: A): Unit = println(a.sayHello) | |
sayHello(new Son {}) | |
sayHello(new Daughter {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment