Purpose of Scala trait extending AnyVal?

607 Views Asked by At

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?

0

There are 0 best solutions below