以下这个URL讲得不错,可以把概念和用途结合起来,

练练手:

http://blog.csdn.net/xiaohai798/article/details/11640427

JAVA反映机制A
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import javax.swing.JOptionPane;

/**

java reflect

*/

public class MyTest {
    public MyTest() {
      String classInfo = JOptionPane.showInputDialog(null, "Input class full path: ");
      try {
        Class cla = Class.forName(classInfo);
        Method[] method = cla.getDeclaredMethods();
        for(Method me:method){
          System.out.println(me.toString());
        }
        System.out.println("*************");
        Field[] field = cla.getDeclaredFields();
        for(Field me:field) {
          System.out.println(me.toString());
        }
      } catch (ClassNotFoundException e) {
        e.printStackTrace();
      }
    }
    public static void main(String[] args) {
      new MyTest();
    }
  }
JAVA反映机制A

JAVA反映机制A

相关文章:

  • 2021-10-14
猜你喜欢
  • 2022-12-23
  • 2021-10-11
  • 2022-02-16
  • 2022-02-20
  • 2021-12-06
  • 2021-07-03
  • 2021-05-14
相关资源
相似解决方案