I have a generic class that looks like this.
public class DAO<T> {
private final Class<T> clazz;
public DAO(Class<T> clazz) {
this.clazz = clazz;
}
}
I use it within a RestFull api powered by Jersey. I use it very often and I have to instanciate it like this for now :
private final DAO<Account> accountDAO = new DAO<>(Account.class);
I would like instantiate it using Jersey's HK2 injection library. Like this
@Inject
private final DAO<Account> accountDAO
I am having trouble finding a way to do that kind of injection with type inference. I have looked at factories (org.glassfish.hk2.api.Factory), but haven't found a way to handle inference.
Any ideas how it could be done?