Skip to content

Instantly share code, notes, and snippets.

@misberner
Created July 21, 2014 17:56
Show Gist options
  • Save misberner/49ab70c425a495b8100f to your computer and use it in GitHub Desktop.
Save misberner/49ab70c425a495b8100f to your computer and use it in GitHub Desktop.
Selftype and Inheritance
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