Created
February 21, 2017 04:26
-
-
Save xuwei-k/aadc3226ef4e2ca3b87a85bc29cc2958 to your computer and use it in GitHub Desktop.
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
| Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_112). | |
| Type in expressions for evaluation. Or try :help. | |
| scala> trait DefaultValue[A]{ def create: A } | |
| defined trait DefaultValue | |
| scala> implicit val intDefault = new DefaultValue[Int]{ def create = 3 } | |
| intDefault: DefaultValue[Int] = $anon$1@68f7aae2 | |
| scala> implicit val stringDefault = new DefaultValue[String]{ def create = "po" } | |
| stringDefault: DefaultValue[String] = $anon$1@71e7a66b | |
| scala> def createValue[A](implicit A: DefaultValue[A]): A = A.create | |
| createValue: [A](implicit A: DefaultValue[A])A | |
| scala> val a = createValue[Int] | |
| a: Int = 3 | |
| scala> val b = createValue[String] | |
| b: String = po |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment