Last active
August 29, 2015 14:24
-
-
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?
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
// 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