Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

  • How else universal trait can be used in Scala?
like image 725
mkUltra Avatar asked Nov 02 '25 13:11

mkUltra


1 Answers

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

like image 162
Alexey Romanov Avatar answered Nov 04 '25 11:11

Alexey Romanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!