mkUltra
mkUltra

Reputation: 3068

What is the use of Universal trait in Scala?

From the documentation, a universal trait can be used for value class:

A value class can only extend universal traits and cannot be extended itself. A universal trait is a trait that extends Any, only has defs as members, and does no initialization. Universal traits allow basic inheritance of methods for value classes, but they incur the overhead of allocation.

Upvotes: 4

Views: 691

Answers (1)

Alexey Romanov
Alexey Romanov

Reputation: 170805

Use in value classes is the only point of universal traits, and all of their limitations are chosen to allow this single use.

Upvotes: 4

Related Questions