constructor cannot distinguish between multiple occurrences of the same primitive type

73 views Asked by At

I am trying to have a class that implements an interface but it cannot determine which argument to put in when there is more than one occurrence of that type in the arguments. Here is a mock version of what I am trying to do. I used @Assisted to try and force the compiler to get the right occurrence but that hasn't worked yet. Any assistance would be appreciated. I can provide the stack trace as well if anyone would like it

public interface C {
}

public class CImpl implements C {
    public CImpl() {
    }

    public CImpl(String tName, @Assisted("min") int min, @Assisted("max") int max) {
    }
}

public interface CFactory {
    C create(String tName, int min, int max);
}

install(new FactoryModuleBuilder().implement(C.class, CImpl.class)
        .build(CFactory.class));
1

There are 1 answers

0
Tavian Barnes On

You need to put a matching

public interface CFactory {
    C create(String tName, @Assisted("min") int min, @Assisted("max") int max);
}