Pattern Matching `@` Symbol

You only include the @ when you want to also deal with the object itself. Hence:

that match{
  case p @ Person(_, age) if p != bill => age
  case Person(_, age) => age - 15
  case _ => println("Not a person")
}

Otherwise, there's no real point in including it.


Regarding the comments for the above answer.

Consider this case class.

case class Employee(name: String, id: Int, technology: String)

while doing pattern matching.

case e @ Employee(_, _, "scala") => e.name // matching for employees with only scala technology ... it works

case x: Employee => x.name // It also works

case e: Employee(_, _, "scala") => e.name // matching for employees with only scala technology ... **wont't work**