给定此Person
案例类:
scala> case class Person(name: String, age: Int) {}
defined class Person
...和这个实例
scala> val b = Person("Kevin", 100)
b: Person = Person(Kevin,100)
是否有理由偏爱此代码(带有@
)
scala> b match {
| case p @ Person(_, age) => println("age")
| case _ => println("none")
| }
age
...在以下?
scala> b match {
| case Person(_, age) => println("age")
| case _ => println("none")
| }
age
也许我错过了的意义/力量@
?
to refer the object itself
?