<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    ivaneeo's blog

    自由的力量,自由的生活。

      BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
      669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
    1.調用構造函數的例子
    /**
         * Invoke a constructor on a class using reflection.
         *
         * @param klass The class.
         * @param classes The classes in the parameter list.
         * @param objects The objects to be used as parameters.
         * @return The object constructed.
         */
        public static Object invokeConstructor(final Class klass, final Class[] classes, final Object[] objects) {
            try {
                Constructor constructor;
                try {
                    constructor = klass.getDeclaredConstructor(classes);
                }
                catch (NoSuchMethodException e) {
                    constructor = klass.getConstructor(classes);
                }
                constructor.setAccessible(true);
                return constructor.newInstance(objects);
            }
            catch (NoSuchMethodException e) {
                throw new RuntimeException(e.getMessage());
            }
            catch (InstantiationException e) {
                throw new RuntimeException(e.getMessage());
            }
            catch (IllegalAccessException e) {
                throw new RuntimeException(e.getMessage());
            }
            catch (InvocationTargetException e) {
                throw new RuntimeException(e.getTargetException().getMessage());
            }
        }

    2.調用域的例子
    /**
         * Get the value of an instance field on an object using reflection.
         *
         * @param instance The instance of the object.
         * @param fieldName The name of the field.
         * @return The object returned by getting the field.
         */
        public static Object invokeGetInstanceField(final Object instance, final String fieldName) {
            try {
                Field field;
                try {
                    field = instance.getClass().getField(fieldName);
                }
                catch (NoSuchFieldException e) {
                    field = instance.getClass().getDeclaredField(fieldName);
                }
                field.setAccessible(true);
                return field.get(instance);
            }
            catch (NoSuchFieldException e) {
                throw new RuntimeException(e.getMessage());
            }
            catch (IllegalAccessException e) {
                throw new RuntimeException(e.getMessage());
            }
        }

    3.調用類方法的例子
    /**
         * Invoke an instance method on an object using reflection.
         *
         * @param instance The instance of the object.
         * @param methodName The name of the method.
         * @param classes The classes in the parameter list.
         * @param objects The objects to be used as parameters.
         * @return The object returned by invoking the method.
         */
        public static Object invokeInstanceMethod(
                final Object instance, final String methodName, final Class[] classes, final Object[] objects) {

            try {
                Method method;
                try {
                    method = instance.getClass().getDeclaredMethod(methodName, classes);
                }
                catch (NoSuchMethodException e) {
                    method = instance.getClass().getMethod(methodName, classes);
                }
                method.setAccessible(true);
                return method.invoke(instance, objects);
            }
            catch (NoSuchMethodException e) {
                throw new RuntimeException(e.getMessage());
            }
            catch (IllegalAccessException e) {
                throw new RuntimeException(e.getMessage());
            }
            catch (InvocationTargetException e) {
                throw new RuntimeException(e.getTargetException().getMessage());
            }
        }

    4.調用靜態方法的例子
    /**
         * Invoke a static method on a class using reflection.
         *
         * @param klass The class.
         * @param methodName The name of the method.
         * @param classes The classes in the parameter list.
         * @param objects The objects to be used as parameters.
         * @return The object returned by invoking the method.
         */
        public static Object invokeStaticMethod(
                final Class klass, final String methodName, final Class[] classes, final Object[] objects) {

            try {
                Method method;
                try {
                    method = klass.getDeclaredMethod(methodName, classes);
                }
                catch (NoSuchMethodException e) {
                    method = klass.getMethod(methodName, classes);
                }
                method.setAccessible(true);
                return method.invoke(klass, objects);
            }
            catch (NoSuchMethodException e) {
                throw new RuntimeException(e.getMessage());
            }
            catch (IllegalAccessException e) {
                throw new RuntimeException(e.getMessage());
            }
            catch (InvocationTargetException e) {
                throw new RuntimeException(e.getTargetException().getMessage());
            }
        }
    posted on 2005-08-04 14:47 ivaneeo 閱讀(409) 評論(0)  編輯  收藏 所屬分類: java魔力
    主站蜘蛛池模板: 亚洲av日韩av无码av| 国产AV无码专区亚洲AV琪琪| 亚洲成av人片在线看片| 精品亚洲成A人在线观看青青| 在线观看片免费人成视频无码| 在线观看AV片永久免费| 亚洲综合无码AV一区二区| 亚洲中文字幕一区精品自拍| 精品在线免费观看| 亚洲国产一级在线观看| 99热亚洲色精品国产88| 免费在线看黄的网站| 亚洲国产精品久久久久婷婷老年 | 日亚毛片免费乱码不卡一区 | 国产日韩精品无码区免费专区国产 | 亚洲成a人片在线观看中文app| 美丽姑娘免费观看在线观看中文版| 国产大片免费观看中文字幕| 亚洲黄色在线电影| 国产日韩一区二区三免费高清| 亚洲av午夜福利精品一区人妖| 免费人成再在线观看网站| 蜜桃视频在线观看免费网址入口| 亚洲精品国精品久久99热一| 精品亚洲福利一区二区| 狠狠色婷婷狠狠狠亚洲综合| 特级毛片aaaa级毛片免费| 日本高清免费中文字幕不卡| 亚洲人成7777| 亚洲福利精品电影在线观看| 色婷婷亚洲一区二区三区| 亚洲人成色7777在线观看不卡 | 久久精品国产免费观看| 国产亚洲精品xxx| 无码区日韩特区永久免费系列| 日日操夜夜操免费视频| 一级成人a做片免费| 国产亚洲人成网站在线观看| 最近2019年免费中文字幕高清| 色婷婷六月亚洲婷婷丁香| 中文字幕免费在线|