I have a question on the combination of reflection and varargs. Out of pure curiosity, I would like to know how I can obtain a reference to a Method that has a varargs parameter. I've tried looking for some information on this subject, but couldn't find any posts in this forum (keyword used in forum search box: reflection). I did find an [url http://today.java.net/pub/a/today/2004/03/08/reflect.html?page=last]article on java.net that explained a few things, but it left me puzzled on this particular issue:
class Foo {
public void methodOne(String param) {
// whatever...
}
public void methodTwo(String ... params) {
// whatever...
}
public void methodTwo(Number param) {
// whatever...
}
}
If I want to get a reference to Method object methodOne, I would do this:
Foo.getClass().getDeclaredMethod("methodOne", String.class);
Without having to iterate over the methods until I find the one that is called "methodTwo" and returns
true on invocation of
isVarargs, how do I get a reference to the methodTwo object that takes the String varargs as parameters?