Created
July 15, 2016 21:49
-
-
Save paulp/b6cd80d1ff413047bb163a69ce8f26b3 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
| package p | |
| sealed trait Bar | |
| final case object Oops extends Bar | |
| final case class Foo(s: String) extends Bar | |
| object Foo { | |
| def apply(x: Double): Bar = if (x.isNaN) Oops else Foo("double") | |
| def apply(x: BigDecimal): Foo = Foo("BigDecimal") | |
| } | |
| object Main { | |
| def main(args: Array[String]): Unit = { | |
| val x1 = Foo(1.1d) | |
| val x2: Foo = Foo(1.1d) | |
| println("x1: " + x1) | |
| println("x2: " + x2) | |
| } | |
| // x1: Foo(double) | |
| // x2: Foo(BigDecimal) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment