jeudi 20 octobre 2022

Java generic parametrized parameter constrained by other parameters

I have a generic class, which has a function that returns an instance of a functional interface:

/**
 * @param <FF> - FF is a functional interface
 */
public abstract class MyFunctionalInterfaceGetter<FF> {
    public abstract <PC, AC> FF getMyFunction(Class<PC> pojoClass, Class<AC> attributeClass);
}

And I have a couple of derived classes:

public class MyGetterGetter extends MyFunctionalInterfaceGetter<java.util.function.Function> {
    public <PC, AC> Function<PC, AC> getMyFunction(Class<PC> pojoClass, Class<AC> attributeClass) {
         ...
    }
}
public class MySetterGetter extends MyFunctionalInterfaceGetter<java.util.function.BiConsumer> {
    public <PC, AC> BiConsumer<PC, AC> getMyFunction(Class<PC> pojoClass, Class<AC> attributeClass) {
         ...
    }
}

And the question:
I do not thing so, but I wanted to know if there is any way to constrain the returning parametrized type from the function parameters at the parent class.
Something like this:

public abstract class MyFunctionalInterfaceGetter<FF> {
    public abstract <PC, AC> FF<PC, AC> getMyFunction(Class<PC> pojoClass, Class<AC> attributeClass);
}

I am using Java-8





Aucun commentaire:

Enregistrer un commentaire