Skip to content

Instantly share code, notes, and snippets.

@paulp
Created July 15, 2016 21:48
Show Gist options
  • Select an option

  • Save paulp/d901e8aa8df09b9d1a7e7ebec6ae5d23 to your computer and use it in GitHub Desktop.

Select an option

Save paulp/d901e8aa8df09b9d1a7e7ebec6ae5d23 to your computer and use it in GitHub Desktop.
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 {
val double2bigDecimal = null
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