Guice with parents

前端 未结 3 652
礼貌的吻别
礼貌的吻别 2021-01-11 18:59

What do I do with Guice when I need to call a parent constructor that is also injectable? e.g. I have an abstract parent class that has a constructor that is injected with a

3条回答
  •  忘掉有多难
    2021-01-11 19:07

    You'd need to do the exact same thing you do if you weren't using Guice... declare any parameters the parent constructor requires as parameters to each child's constructor as well, and pass those to super.

    So if your abstract parent class's constructor takes a Foo, a child class's constructor needs to look like:

    @Inject public ChildClass(Foo foo, Bar bar) {
      super(foo);
      this.bar = bar;
      ...
    }
    

提交回复
热议问题