java 反射

package com.googlepages.smallnest.facet;

 

import java.awt.print.Printable;

import java.lang.reflect.InvocationTargetException;

import java.lang.reflect.Method;

 

public class DynaTest {

public static void main(String[] args) throws ClassNotFoundException,

SecurityException, NoSuchMethodException, IllegalArgumentException,

IllegalAccessException, InvocationTargetException {

Class cla = Class.forName("com.googlepages.smallnest.facet.Test");

Test t=new Test();

for(int i=0;i<4;i++){

Method method1 = cla.getMethod("print"+i,String.class);

method1.invoke(t,"11");

}

}

 

 

 

}

class Test{

public void print0(String sb){

System.out.println(sb);

}

public void print1(String sb){

System.out.println(sb);

}

public void print2(String sb){

System.out.println(sb);

}

public void print3(String sb){

System.out.println(sb);

}

 

}


你可能感兴趣的:(java 反射)