Created
July 21, 2014 17:56
-
-
Save misberner/49ab70c425a495b8100f to your computer and use it in GitHub Desktop.
Selftype and Inheritance
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
abstract class MyComparable[D <: MyComparable[D]] { | |
this: D => | |
def <=(other: D) | |
def >=(other: D) = (other <= this) // would fail without selftype | |
// ... | |
} | |
abstract class MyEnhancedComparable[D <: MyEnhancedComparable[D]] extends MyComparable[D] { | |
// Omitting this line results in: | |
// - illegal inheritance; self-type MyEnhancedComparable[D] does not conform to MyComparable[D]'s | |
// selftype D | |
this: D => | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment