43: Objects: Companion Objects (Introduction to Scala 3)

Опубликовано: 16 Май 2026
на канале: Ziverge
31
1

In Scala, a companion object is just an object that declared in the same file as a class that has the same name as the object. With this approach, the class is also known as the companion of the object.

A great thing about this approach is that the companions can access each other's private members (fields and methods). I think of this as them being married and sharing a joint bank account.