Search code examples
javadependency-injectiondagger-2

Dagger Error: "The @AssistedFactory-annotated type should contain a single abstract, non-default method but found multiple"


I'm learning to use Dagger and assisted injection, and I have the following factory interface

@AssistedFactory
public interface IFactory{

  HandlerA createHandlerA (String path);
  HandlerB createHandlerB (String path);
  HandlerC createHandlerC (String path);
  HandlerD createHandlerD (String path);
}

And when I try to compile, I get a message saying:

The @AssistedFactory-annotated type should contain a single abstract, non-default method but found multiple

The API docs say the same thing, but I don't really get what it means, and would really appreciate any explanation, as well as a suggestion and how to fix/avoid it in the future. Thank you!


Solution

  • It says you want

    @AssistedFactory
    public interface IFactoryA {    
      HandlerA createHandlerA (String path);
    }
    
    @AssistedFactory
    public interface IFactoryB {
      HandlerB createHandlerB (String path);
    }
    
    @AssistedFactory
    public interface IFactoryC {
      HandlerC createHandlerC (String path);
    }
    
    @AssistedFactory
    public interface IFactoryD {
      HandlerD createHandlerD (String path);
    }