Nested trait in class constructor in scala

I'm playing around with scala (scala 2.8). Suppose I have a class with a nested trait, and want to use that nested trait as the type for a parameter in the class's constructor. Is that even possible? This is the closest I've come:

class OuterClass(traitParam:OuterClass#InnerTrait) {
  trait InnerTrait { }
  val y:InnerTrait = traitParam
}

Without the third line that even compiles, but as soon as I try to actually use the traitParam as an InnerTrait I get a compiler error:

type mismatch; found: OuterClass#InnerTrait required: OuterClass.this.InnerTrait.

I can't figure out what (if anything) I could do. Doing

class OuterClass(traitParam:OuterClass.this.InnerTrait)

instead, as the error message might suggest, does not compile. Do I have any choice other than to move InnerTrait outside of OuterClass? If you're wondering why I would want to do this, the answer is that in my actual code, the equivalent of OuterClass has type parameters which would then be used in InnerTrait. If I move it outside, then I have to restate the type parameters every time I reference the inner trait.

7
задан Micah 3 September 2010 в 01:56
поделиться