I am looking for 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 problem is that you cannot just call this method with:
myMethod(ImplA.class, ImplB.class);
It is simply not accepted. Is it true that optional parameters and generics cannot be combined? I can not find any example.
source share