// Collection of code snippets by Arne Vajhøj 
// (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
case class X(val a: Int)

case class Y(val b: Int)

def f(o: X|Y): Unit = {
  // the Java way
  if(o.isInstanceOf[X]) {
    println("a = " + o.asInstanceOf[X].a)
  }
  if(o.isInstanceOf[Y]) {
    println("b = " + o.asInstanceOf[Y].b)
  }
  // the Scala way
  println(o match
            case X(a) => "a = " + a
            case Y(b) => "b = " + b
          )
}

object Ext30 {
  def main(args: Array[String]): Unit = {
    f(new X(123))
    f(new Y(456))
  }
}
