Reputation: 5449
I'm not sure why this won't compile - I'm trying to use an inner class (or trait) such that other objects can work with the resulting "RequestReturn", but only Trait Request and it's descendants can construct the object in the first place. I may be taking the wrong approach but shouldn't this code logically work? I've flagged the RequestReturn constructor as protected[Request] so it stands to reason that class RequestContinue would have the ability to call the constructor also.
trait Request {
class RequestReturn protected[Request](val x:Any)
def fulfill(item:Boolean):RequestReturn = new RequestReturn(item) //this line compiles
}
trait RequestContinue extends Request{
override def fulfill(item:Boolean):RequestReturn = new RequestReturn(item) //this won't compile
}
Error:(19, 54) constructor RequestReturn in class RequestReturn cannot be accessed in trait RequestContinue Access to protected constructor RequestReturn not permitted because enclosing trait RequestContinue in package .... is not a subclass of class RequestReturn in trait Request where target is defined override def fulfill(item:Boolean):RequestReturn = new RequestReturn(item) ^
Upvotes: 1
Views: 223