programmatically setting the `type` of an abstract type
class MyModel(var username:String, var password:String) e开发者_JS百科xtends FrameworkModel
object MyModelQuery extends FrameworkQuery {
type T = MyModel
}
trait FrameworkQuery {
type T
//do something with that type
}
So I get a class and an object where the latter is mixing in a trait which is defined as an abstract type. Is there a way I could programmatically set the type
to the type of MyModel class, so the client would not need to? ie "object MyModelQuery extends FrameworkQuery" would take care of it
Could you achieve a similar effect by just nesting the query in the model?
trait FrameworkModel {
val model = this
trait FrameworkQuery {
type T = model.type
def getModel: T = model
}
}
class UserModel extends FrameworkModel {
// model stuff...
object UserQuery extends FrameworkQuery {
// query stuff...
}
}
trait T{
type X = this.type
def x: X = this
}
object A extends T{
def b = "Yep"
}
scala> A.x.b
res0: java.lang.String = Yep
精彩评论