« Return to Thread: self type is not inherited

Re: [scala] self type is not inherited

by Sean McDirmid :: Rate this Message:

Reply to Author | View in Thread

Another use case: self types are useful when inheritance isn't
possible, e.g., the virtual class pattern:

type T <: TImpl
trait TImpl { self : T =>
  ...
}

The limitations of self types are well known: they don't work outside
the instance (TImpl can't be automatically coerced to T via only a
self type) and they are very verbose (once you use the self type, you
have to re-affirm the annotation over and over again). On the other
hand, a self def (the alternative to a self type) can't act as a
stable identifier and doesn't allow for abstract override (because the
contract is informal).

On Wed, Oct 15, 2008 at 4:17 AM, David MacIver <david.maciver@...> wrote:
> There are sometimes advantages to using the self type. e.g.
> inheritance at that point can change the initialisation and override
> orders.

 « Return to Thread: self type is not inherited