Understanding Case class and Traits in Scala

前端 未结 3 583
一生所求
一生所求 2021-02-08 02:53

I have a simple trait as defined below:

trait MyTrait {

  def myStringVal: String

}

My case class which implements this trait is as below:

3条回答
  •  灰色年华
    2021-02-08 03:03

    Case classes are different -- some default methods are generated for them. This includes val getters for the parameters. Think of case classes as POJOs -- this is a useful bit of syntactic sugar, since they don't need private members.

    Some other useful methods are generated too, for example copy, toString, apply and unapply.

提交回复
热议问题