How is pattern matching in Scala implemented at the bytecode level?
How is pattern matching in Scala implemented at the bytecode level? Is it like a series of if (x instanceof Foo) constructs, or something else? What are its performance implications? For example, given the following code (from Scala By Example pages 46-48), how would the equivalent Java code for the eval method look like? abstract class Expr case class Number(n: Int) extends Expr case class Sum(e1: Expr, e2: Expr) extends Expr def eval(e: Expr): Int = e match { case Number(x) => x case Sum(l, r) => eval(l) + eval(r) } P.S. I can read Java bytecode, so a bytecode representation would be good