Skip to content

Instantly share code, notes, and snippets.

@ldacosta
Last active August 29, 2015 14:24
Show Gist options
  • Save ldacosta/12c8b819399db99f7128 to your computer and use it in GitHub Desktop.
Save ldacosta/12c8b819399db99f7128 to your computer and use it in GitHub Desktop.
Want to mix ATrait below to get functionalities on MyClass. But there is AType defined in ATrait that I want to have access to - at declaration time. Is this possible?
// Stuff below doesn't compile
trait ATrait {
val something: Int
// <some stuff here>
case class AType[T](value: T)
}
case class MyClass(something: Int, f: AType => Int) extends ATrait // error: not found: type AType
// this version needs _something_ to be defined:
object Wrapper extends ATrait { // error: something undefined
case class MyClass(f: AType => Int) extends ATrait
}
// is this the only way to do it?
case class AType[T](value: T)
trait ATrait {
// <some stuff here>
}
case class MyClass(f: AType => Int) extends ATrait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment