Example demostrating how to use trait to provide effective implementation of linked list while keeping encapsulation
1 package org.apidesign.effectivelist
3 /** A member of a {@link List} that makes keeping references
4 * to previous and next items in the list effective.
6 trait Listable[T <: Listable[T]] {
7 private[effectivelist] var prev : T = _
8 private[effectivelist] var next : T = _