Is there any advantage to definining a val over a def in a trait?

前端 未结 4 1320
失恋的感觉
失恋的感觉 2021-02-05 16:56

In Scala, a val can override a def, but a def cannot override a val.

So, is there an advantage to declaring a trait

4条回答
  •  甜味超标
    2021-02-05 17:00

    A val expression is evaluated once on variable declaration, it is strict and immutable.

    A def is re-evaluated each time you call it

提交回复
热议问题