What are the pros of using traits over abstract classes?

前端 未结 7 1464
-上瘾入骨i
-上瘾入骨i 2021-01-30 10:12

Can someone please explain traits in Scala? What are the advantages of traits over extending an abstract class?

7条回答
  •  情话喂你
    2021-01-30 10:33

    This site gives a good example of trait usage. One big advantage of traits is that you can extend multiple traits but only one abstract class. Traits solve many of the problems with multiple inheritance but allow code reuse.

    If you know ruby, traits are similar to mix-ins

提交回复
热议问题