I not exactly sure what you want to achieve. Let's say your TFactory
was given as in your first example:
trait T
trait TFactory {
def build(): T
}
Then the build
method obviously cannot take any parameter. If you want to configure your factory, you can have a factory-factory:
class A(x: Int) extends T
object A {
def apply(x: Int): TFactory = new TFactory {
def build() = new A(x)
}
}
val factory = A(33)
val t = factory.build()
If you define TFactory
simply to be a function from ()
to T
, you can use currying
type TFactory = () => T
object A {
def apply(x: Int)(): T = new A(x)
}
val factory: TFactory = A(33) _
val t = factory()