<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魔力
    主站蜘蛛池模板: 久久久久久久久久久免费精品| 亚洲资源在线观看| 中文字幕免费在线观看| 日本19禁啪啪无遮挡免费动图| 在线观看免费无码视频| 四虎成人免费观看在线网址 | 欧洲乱码伦视频免费| 亚洲国产a∨无码中文777| 伊人久久亚洲综合影院| 亚洲嫩模在线观看| 黄页网址大全免费观看12网站| 波多野结衣免费在线观看| 亚洲AV永久精品爱情岛论坛| 国产vA免费精品高清在线观看| 日本免费中文字幕在线看| 亚洲AV成人无码网天堂| 亚洲AV无码一区二区三区电影 | 亚洲天堂一区在线| 亚洲精品动漫免费二区| 亚洲男同gay片| 亚洲男人第一无码aⅴ网站| 国产线视频精品免费观看视频| 久久久久亚洲精品无码系列| 蜜臀AV免费一区二区三区| 亚洲情侣偷拍精品| 日本一道本不卡免费 | 国产做床爱无遮挡免费视频| 一级毛片免费观看不收费| 亚洲动漫精品无码av天堂| 日本h在线精品免费观看| 亚洲精品久久无码| 亚洲视频免费在线看| 亚洲国产日韩精品| 亚洲成a人片在线观看日本麻豆| 亚洲AV色吊丝无码| 1000部羞羞禁止免费观看视频| 亚洲欧洲免费无码| 国产gv天堂亚洲国产gv刚刚碰| 7m凹凸精品分类大全免费| 国产精品亚洲精品久久精品| 国产精品亚洲A∨天堂不卡|