1

Sometimes in Scala/Scala.js I see trait Foo extends AnyVal { ... } – what's the meaning and purpose of extends AnyVal here?

I'm aware of value classes, and that they can not extend traits that extend AnyRef, so using extends AnyVal would make sense for that use case.

But what if we don't use value classes to extend such a trait? Are there any performance advantages for traits to extend AnyVal on their own?

Nikita
  • 2,924
  • 1
  • 19
  • 25
  • Nikita, It would probably be easier to answer your question if you provided some specific examples of such `trait`s that make you wonder. P.S. I don't think there is any performance advantage except for value classes. – SergGr Dec 11 '17 at 03:07
  • 1
    1. Is it really `extends AnyVal`, not `Any`? 2. If you don't extend such a trait with a value class it doesn't mean nobody does. – Alexey Romanov Dec 11 '17 at 06:49

0 Answers0