I am not 100% sure, but I donβt think you can do what you are trying to do here. Since C not generic, you cannot use C<T> . Lots of code below, but tl; dr select option 3 . All that really changes at the end is how many BatchSynchronisedPool objects you need to create, which is not really a significant overhead ...
1. Save the parameter of type <T> general type in the method, send Callable<T> and check the runtime of the types , for example, your original solution, in the class that implements this interface.
public interface BatchSynchronisedPool<R extends Runnable> { void execute(R runnable, Object batchIdentifier); public <T> Future<T> submit(Callable<T> callable, Object batchIdentifier); } public class MyBSP<R, C> implements BatchSynchronisedPool<R, C> { void execute(R runnable, Object batchIdentifier) { ... } public <T> Future<T> submit(Callable<T> callable, Object batchIdentifier) {
2. Save the parameter of type <T> general type in the method, send C and perform the cast , as you said, in the class that implements this interface.
public interface BatchSynchronisedPool<R extends Runnable, C extends Callable> { void execute(R runnable, Object batchIdentifier); public <T> Future<T> submit(Class<T> cls, C callable, Object batchIdentifier); } public class MyBSP<R, C> implements BatchSynchronisedPool<R, C> { void execute(R runnable, Object batchIdentifier) { ... } public <T> Future<T> submit(Class<T> cls, C callable, Object batchIdentifier) {
3. Create a new BatchSynchronisedPool for each type of T that you are trying to send, specifying T as the generic type parameter for the class. Then, every time you want to call submit for a different type, you need to create a new instance of BatchSynchronisedPool .
public interface BatchSynchronisedPool<T, R extends Runnable, C extends Callable<T>> { void execute(R runnable, Object batchIdentifier); public Future<T> submit(C callable, Object batchIdentifier); } public class MyBSP<T, R, C> implements BatchSynchronisedPool<T, R, C> { void execute(R runnable, Object batchIdentifier) { ... } public Future<T> submit(C callable, Object batchIdentifier) {