I am searching for an elegant solutions for the following problem:
//one interface
public interface MyInterface () {
}
//two implementations
public class ImplA implements MyInterface (){
}
public class ImplB implements MyInterface () {
}
In another class:
//one generic method
public void myMethod(Class<MyInterface>... myTypes) {
for (Class<MyInterface> myType : myTypes) {
System.err.println("my Type:" +myType);
}
}
The issue is that you cannot simply invoke this method with:
myMethod(ImplA.class, ImplB.class);
This is just simply not accepted. Is it true that optional parameter and generics can’t be combined? I cannot find any example.
I would try
Class<MyInterface>has to beMyInterface.classnot a subclass.