public static void method(Set<?>... sets){}
Depending on program flow, above method is called with two sets, or with three sets, or more. (Not known at compile time).
Is there a way to constructing the argument list “on the fly”?
sets is of type Set< ?>[ ]
Following was not fruitful:
Set<Set<Integer>> varargs = new HashSet<Set<Integer>>();
(method recognizes varargs just as one set -> no solution)
Set<Integer>[] varargs = new HashSet<Integer>[2];
returns
"Cannot create generic array of HashSet<Integer>"
I would like to construct an array of arguments, while array size and content is filled at runtime.
1 Answer