Case Class default apply method

前端 未结 3 2055
别跟我提以往
别跟我提以往 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:45

    You may also give your firstName class parameter a default value. So you can create an instance with passing no parameter.

    Example:

    case class CasePerson(firstName : String = "XYZ")
    val person = CasePerson()
    

提交回复
热议问题