Case Class default apply method

前端 未结 3 2064
别跟我提以往
别跟我提以往 2021-01-02 13:09

Assuming we have the following case class:

case class CasePerson(firstName: String)

And we also define a companion object for it:



        
3条回答
  •  醉酒成梦
    2021-01-02 13:27

    Scala case classes are syntactic sugar. When you create a case class the Scala compiler will create a companion object with an apply and an unapply method for you, which you can then use as if it simply exists. Here is a link to more in depth information on case classes.

提交回复
热议问题