Docs API
Scala 3/Reference/Dropped Features/Dropped: Class Shadowing
Edit this page on GitHub

Dropped: Class Shadowing

Scala 2 so far allowed patterns like this:

class Base {
 class Ops { ... }
}

class Sub extends Base {
 class Ops { ... }
}

Scala 3 rejects this with the error message:

6 | class Ops { }
 | ^
 |class Ops cannot have the same name as class Ops in class Base
 | -- class definitions cannot be overridden

The issue is that the two Ops classes look like one overrides the other, but classes in Scala 2 cannot be overridden. To keep things clean (and its internal operations consistent) the Scala 3 compiler forces you to rename the inner classes so that their names are different.

More details

Contributors to this page

AltStyle によって変換されたページ (->オリジナル) /