Nikita
Nikita

Reputation: 2943

Purpose of Scala trait extending AnyVal?

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?

Upvotes: 1

Views: 649

Answers (0)

Related Questions