<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无码一区二区三区天堂| 日本免费一区二区三区最新vr| 国产在亚洲线视频观看| 亚洲性一级理论片在线观看| 1000部啪啪未满十八勿入免费| 亚洲午夜精品久久久久久人妖| 久久A级毛片免费观看| 亚洲国产精品人久久电影| 无码中文在线二区免费| 亚洲国产成人久久精品大牛影视| 国产美女被遭强高潮免费网站| 免费亚洲视频在线观看| 国产午夜亚洲精品午夜鲁丝片| 野花香高清视频在线观看免费 | 免费无码毛片一区二区APP| 亚洲成aⅴ人在线观看| 免费看片A级毛片免费看| 色费女人18女人毛片免费视频| 久久精品夜色噜噜亚洲A∨| 免费毛片a线观看| 亚洲天堂男人影院| 免费一级毛片不卡在线播放| a级毛片黄免费a级毛片| 亚洲人成影院在线高清| 亚洲А∨精品天堂在线| 日韩电影免费在线观看中文字幕| 亚洲一区在线免费观看| 国产成人精品日本亚洲专区 | 免费看又黄又爽又猛的视频软件| 亚洲精品高清国产一线久久| 四虎在线视频免费观看视频| 亚洲精品无码少妇30P| 国产精品亚洲аv无码播放| 无码少妇一区二区浪潮免费| 日韩在线视频线视频免费网站| 亚洲永久中文字幕在线|