Created
January 26, 2015 09:28
-
-
Save ktoso/b36cb880ef16683eed29 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Box { | |
| type T | |
| private var t: T = _ | |
| def put(t: T) = this.t = t | |
| def get = t | |
| } | |
| { // traits only | |
| trait IntBox extends Box { override type T = Int } | |
| val intBox = new IntBox {} | |
| intBox.put(1) | |
| val t = intBox.get // inferred: Int | |
| def extract(box: Box): box.T = box.get | |
| val got = extract(intBox) // inferred: Int | |
| } | |
| { // class IntBox | |
| class IntBox extends Box { override type T = Int } | |
| val intBox = new IntBox {} | |
| intBox.put(1) | |
| val t = intBox.get // inferred: intBox.T | |
| def extract(box: Box): box.T = box.get | |
| val got = extract(intBox) // inferred: intBox.T | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment