如果类里有重载或不定长度参数的方法如何进行对方法的反射?

如果类里有重载的方法如何进行对方法的反射?

如题:
比如说:
[code="java"]
package com.tom.blog.monicc.test.reflect

public class TestDao{

public void printTest(){
    System.out.println("test");
}

public void printTest(String[] strings){
    System.out.println("test");
    for(String str : strings){
        System.out.println("str[]: " + str);
    }
}

}
[/code]

那么我要通过反射使用printTest(String[] strings)方法要怎样才可以,我现在是无论怎么只是找到那个无参数的方法。

还有另外的一种情况,在我们的Dao类里有很多的用了5.0以后出现的不定长度参数,像是:

[code="java"] ...
public void printTest(String... strings){
System.out.println("test");
for(String str : strings){
System.out.println("str[]: " + str);
}
}
...[/code]

那么请问一下在这种情况下怎么才能得到这个方法?我用反射的话总是NoSuchMethodException。
他总找的是printTest()这个方法。

我在网上查不到相关的信息,希望有人能指点一下,谢谢!

[code="java"]public class Test {

public void methodOne(String... args) {
    System.out.println("1");
}

public void methodOne(String arg) {
    System.out.println("2");
}

public void methodTwo(String[] args) {
    System.out.println("3");
}

public static void main(String[] args) throws Exception {
    Test test = new Test();

    Method method1 = Test.class.getMethod("methodOne", new Class[] { String[].class });
    method1.invoke(test, new Object[] { new String[] { "s" } });

    Method method2 = Test.class.getMethod("methodOne", new Class[] { String.class });
    method2.invoke(test, new Object[] {"s"});

    Method method3 = Test.class.getMethod("methodTwo", new Class[] { String[].class });
    method3.invoke(test, new Object[] { new String[] { "s" } });
}

}[/code]

[code="java"]public class Test {
public void methodOne(String... args) {
System.out.println("1");
}

public void methodTwo(String[] args) {
    System.out.println("2");
}

public static void main(String[] args) throws Exception {
    Test test = new Test();

    Method method2 = Test.class.getMethod("methodOne", new Class[] { String[].class });
    method2.invoke(test, new Object[] { new String[] { "s" } });

    Method method = Test.class.getMethod("methodTwo", new Class[] { String[].class });
    method.invoke(test, new Object[] { new String[] { "s" } });
}

}[/code]

也就是: String... 其实等同于 String[]

上面的代码包含了重载.