Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save paulp/b6cd80d1ff413047bb163a69ce8f26b3 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 {
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