Professional Documents
Culture Documents
1
the new de_nitions of IterableBuffer[T]. Mixing a class C
into another class D is legal only as long as D's superclass
is a subclass of C's superclass. Thus, the mixin composition
in the program above is well-formed, since the superclass
of IterableStack is a subclass of the superclass of
IterableBuffer.
Scala enforces this requirement for type-safety reasons.
Since only the delta of a class is _copied_ into another class
by a mixin-class composition, it could otherwise happen that
some mixed-in members refer to inherited members which
are not present in the new context, yielding a _method not
found_ exception.
Ambiguities In Scala, every class inherits exactly from
one superclass and acquires class members from multiple
other classes via mixin-based class composition. Imagine for
instance the following subclass of Buffer which introduces
a method sameElements together with an internally used
forall method.