I\'d like to implement a function with both generics and varargs.
public class Question {
public static void doNastyThingsToClasses(Class
OK, so finally I end up throwing the varargs away:
public class Question {
public static void doNastyThingsToClasses(Class parent, List> classes) {
/******/
for(Class extends A> clazz : classes) {
System.out.println(clazz);
}
}
public static class NotQuestion {
}
public static class SomeQuestion extends Question {
}
public static void main(String[] args) {
ArrayList> classes = new ArrayList>();
classes.add(Question.class);
classes.add(SomeQuestion.class);
classes.add(NotQuestion.class);
doNastyThingsToClasses(Object.class, classes);
ArrayList> clazzes = new ArrayList>();
clazzes.add(Question.class);
clazzes.add(SomeQuestion.class);
clazzes.add(NotQuestion.class); // yes, this will _not_ compile
doNastyThingsToClasses(Question.class, clazzes);
}
}
The only flaw is the long code for populating the collection used to carry function's arguments.