我正在为以下问题寻找一个优雅的解决方案:
//one interface
public interface MyInterface () {
}
//two implementations
public class ImplA implements MyInterface (){
}
public class ImplB implements MyInterface () {
}
在另一个班级:
//one generic method
public void myMethod(Class<MyInterface>... myTypes) {
for (Class<MyInterface> myType : myTypes) {
System.err.println("my Type:" +myType);
}
}
问题是您不能简单地使用以下方法调用此方法:
myMethod(ImplA.class, ImplB.class);
这只是不被接受。可选参数和泛型不能结合是真的吗?我找不到任何例子。