Scala 3 — Book



In Scala 2, methods can be defined inside classes, traits, objects, case classes, and case objects. But it gets better: In Scala 3 they can also be defined outside any of those constructs; we say that they are “top-level” definitions, since they are not nested in another definition. In short, methods can now be defined anywhere.

Many features of methods are demonstrated in the next section. Because main methods require a little more explanation, they’re described in the separate section that follows.

Contributors to this page: