adhocExtensions
Where imported, ad hoc extensions of non-open classes in other compilation units are allowed.
Why control the feature? Ad-hoc extensions should usually be avoided since they typically cannot rely on an "internal" contract between a class and its extensions. Only open classes need to specify such a contract. Ad-hoc extensions might break for future versions of the extended class, since the extended class is free to change its implementation without being constrained by an internal contract.
Why allow it? An ad-hoc extension can sometimes be necessary, for instance when mocking a class in a testing framework, or to work around a bug or missing feature in the original class. Nevertheless, such extensions should be limited in scope and clearly documented. That's why the language import is required for them.
Attributes
- Source
- language.scala
- Graph
-
- Supertypes
- Self type
-
adhocExtensions.type