Simulate partial type parameter inference with implicits?

后端 未结 2 1438
-上瘾入骨i
-上瘾入骨i 2021-01-06 07:41

I\'m making a simple dependency injection framework, for constructor injection, in Scala. The idea is that objects that are DI\'d put their required services in their constr

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-06 08:11

    trait Construct[T, A] {
     def apply(arg: A): T
    }
    
    class Constructor[T]{
      def apply[A](arg : A)(implicit construct : Construct) = construct(arg)
    }
    
    object Constructor {
     def apply[T] = new Constructor[T]
    }
    
    Constructor[T]("arg")
    

提交回复
热议问题