zoukankan      html  css  js  c++  java
  • 反射3

    package reflect.corecode;
    
    import java.lang.reflect.Field;
    import java.lang.reflect.Method;
    
    public class TestOne {
    
        public static void main(String[] args) {
            
            /**
             * 
             * 反射
             * 动态操纵Java代码,被大量应用于Javabean中。
             * 
             * getFields  当前类及其超类的公有域
             * getDeclaredFields 当前类的所有域
             * 
             * getMethods 当前类及其超类的公有方法
             * public Method[] getDeclaredMethods() throws SecurityException { 当前类的所有方法
             * getMethod(String arg0, Class... arg1) 获取当前类及超类的方法
             * 
             * 
             * Method类中invoke方法
             * invoke(Object arg0, Object... arg1)
             */
            
            ///////////////////////////////book
            System.out.println(Double[].class.getName());
            
            Man man = new Man();
            man.setAge(11); 
            Class class1 = man.getClass();
            Field[] field1 = class1.getFields();
            Field[] field2 = class1.getDeclaredFields();
            
            Method[] method1 = class1.getMethods();
            Method[] method2 = class1.getDeclaredMethods();
            try {
                Method method3 = class1.getMethod("getAge", null);  //get方法
                Method method4 = class1.getMethod("setAge", int.class); //set方法
                Object value = method3.invoke(man, null);
                System.out.println("----->>"+method3);
            } catch (Exception e) {
                e.printStackTrace();
            } 
            
        }
        
        
        
    
    }
  • 相关阅读:
    c++ this *this
    名称空间
    c++ 静态持续变量
    c++ 数组
    c++ 头文件
    实例化和具体化详解
    在linux下安装eclipse以及运行c++程序的安装步骤
    在centos (linux) 搭建 eclipse c++开发分环境
    Linux上使用Qt Creator进行C/C++开发
    使用Qt Creator 2.60编写C/C++程序
  • 原文地址:https://www.cnblogs.com/lxh520/p/9082386.html
Copyright © 2011-2022 走看看