<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魔力
    主站蜘蛛池模板: 91成人在线免费视频| 成人无码视频97免费| 免费大片黄在线观看| 亚洲日产2021三区| 亚洲一卡二卡三卡| 亚洲中文字幕无码一区| 亚洲bt加勒比一区二区| 亚洲一区二区三区免费视频| 久久精品国产亚洲AV未满十八| 免费在线观看一区| 久久久99精品免费观看| 三年片在线观看免费观看高清电影| 国产在线98福利播放视频免费| 亚洲情a成黄在线观看| 亚洲国产成人久久精品动漫| 中文字幕 亚洲 有码 在线| 国产成人高清亚洲一区91 | 真实乱视频国产免费观看| 无人在线观看免费高清| 国产三级在线观看免费| 亚洲国产精品碰碰| 亚洲日本精品一区二区| 亚洲AV综合色区无码一二三区| av午夜福利一片免费看久久| 免费专区丝袜脚调教视频| 国产免费观看黄AV片| 久久亚洲国产精品一区二区| 亚洲日本久久一区二区va| 一级毛片试看60分钟免费播放| 99re免费在线视频| 日韩免费无码视频一区二区三区| 免费无码A片一区二三区| 18禁免费无码无遮挡不卡网站| 四虎成人精品在永久免费| 久久久久亚洲精品影视| 亚洲av无码一区二区三区四区 | 成人免费网站视频www| 1a级毛片免费观看| 亚洲国产a级视频| 亚洲一级大黄大色毛片| 91在线视频免费观看|