1、
package reflectionZ; import java.lang.reflect.Constructor;
import java.lang.reflect.Method; public class Treflection05
{
// 第17讲 【20:40】之后 public static void main(String[] args) throws Exception
{
Tinfo info = new Tinfo();
Class<?> clazz = Class.forName(info.FclassPath);
Object obj = clazz.newInstance(); Class<?> clazzParameter = Class.forName(info.FparameterType);
Constructor<?> constructor = clazzParameter.getConstructor(String.class);
Object objParameter = constructor.newInstance(info.FparameterVal); Method method = clazz.getMethod(info.Fmethod, clazzParameter);
method.invoke(obj, objParameter);
}
} class Dog
{
public void Cry(String name)
{
System.out.println("Cry : "+name);
}
} class Tinfo
{
public String FclassPath = "reflectionZ.Dog";
public String Fmethod = "Cry";
public String Fparameter = "name";
public String FparameterType = "java.lang.String";
public String FparameterVal = "小狗狗";
}
2、