0

I have two traits A and B where A's self type is B.

trait A {
    self: B =>
}

trait B

How would I now construct a factory method for implementations of Trait A with Trait B and its sub-types are taken as a type parameter like this?

def factory[T <: B](args): A with B
rogue-one
  • 11,259
  • 7
  • 53
  • 75
  • Possible duplicate of [Dynamic mixin in Scala - is it possible?](http://stackoverflow.com/questions/3254232/dynamic-mixin-in-scala-is-it-possible) – LaloInDublin May 01 '16 at 20:16
  • Did you try `new A with B`? What is the question? – Dima May 02 '16 at 00:25
  • @Dima question is how to create a factory method for A with B and its subtypes taken as a type parameter which is already explained in the original question. – rogue-one May 02 '16 at 01:57
  • @LaloInDublin I think this question and the other question is largely similar except in my case A and B are concrete types with B additionally type bounded. In the other case I presume A and B are unbounded types. If that is the case both the questions are significantly different but have commonality of dynamic mixin. – rogue-one May 02 '16 at 02:06
  • @mig-foxbat I would try expanding the question with some examples what is going to be constructed. Are there e.g. traits `trait B1 extends B` and `trait B2 extends B` and the factory is going to construct `A with B1` / `A with B2` ? – mirelon May 06 '16 at 16:20

0 Answers0