Java variadic function parameters
- by Amir Rachum
Hi,
I have a function that accepts a variable number of parameters:
foo (Class... types);
In which I get a certain number of class types. Next, I want to have a function
bar( ?? )
That will accepts a variable number of parameters as well, and be able to verify that the variables are the same number (that's easy) and of the same types (the hard part) as was specified in foo.
How can I do that?
Edit: to clarify, a call could be:
foo (String.class, Int.class);
bar ("aaa", 32); // OK!
bar (3); // ERROR!
bar ("aa" , "bb"); //ERROR!
Also, foo and bar are methods of the same class.