Skip to content

Instantly share code, notes, and snippets.

@rightfold

rightfold/a Secret

Created December 27, 2014 12:11
Show Gist options
  • Save rightfold/758838e2a27e4c8e6fb9 to your computer and use it in GitHub Desktop.
Save rightfold/758838e2a27e4c8e6fb9 to your computer and use it in GitHub Desktop.
scala> class A {
| case object O
| }
defined class A
scala> val (x, y) = (new A, new A)
x: A = A@543e710e
y: A = A@57f23557
scala> x.O match { case y.O => 1; case x.O => 2 }
<console>:10: error: pattern type is incompatible with expected type;
found : y.O.type
required: x.O.type
x.O match { case y.O => 1; case x.O => 2 }
^
scala> x.O.asInstanceOf[Any] match { case y.O => 1; case x.O => 2 }
res2: Int = 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment