Created
February 7, 2014 20:53
-
-
Save kevinwright/8871644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Proletariat { | |
type BigNumberT | |
def retirementAge: BigNumberT | |
val bippy = "hi mum" | |
def twiddle = 42 | |
def twaddle = 1 | |
} | |
trait BiggerTwaddle { | |
def twaddle = 3 | |
} | |
class Oppressor(@proxy val worker: Proletariat) extends BiggerTwaddle { | |
val twiddle = 69 | |
} | |
//// expands to: | |
class Oppressor(val worker: Proletariat) extends BiggerTwaddle { | |
//This type delegate only works here because the delegated worker is a stable type | |
//possibly a Yorkshireman? | |
type BigNumberT = worker.BigNumberT | |
def retirementAge = worker.retirementAge | |
val bippy = worker.bippy | |
def twiddle = 69 //don't delegate, already defined | |
//twaddle already inhereted, so don't delegate | |
} | |
// Sample usage | |
val blueCollarWorker = new Proletariat { | |
type BigNumberT = Long | |
val retirementAge = 96L | |
} | |
val capitalism = new Oppressor(blueCollarWorker) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment