集册 Java实例教程 设置构造函数可访问以进行反射

设置构造函数可访问以进行反射

欢马劈雪     最近更新时间:2020-01-02 10:19:05

480
设置构造函数可访问以进行反射


//package com.nowjava;/** 来 自 n o w j a v a . c o m**/

import java.lang.reflect.Constructor;

import java.lang.reflect.Field;

import java.lang.reflect.Method;


public class Main {

    public static Field setAccessible(Field f)

    /*    */throws NoSuchFieldException, SecurityException,

            IllegalArgumentException, IllegalAccessException

    /*    */{

        /* 44 */

        f.setAccessible(true);

        /* 45 */

        Field modifiersField = Field.class.getDeclaredField("modifiers");

        /* 46 */

        modifiersField.setAccessible(true);

        /* 47 */

        modifiersField.setInt(f, f.getModifiers() & 0xFFFFFFEF);

        /* 48 */

        return f;

        /*    *//** 来 自 n o w    j a v a  . c o m**/

    }


    public static Method setAccessible(Method m)

    /*    */throws SecurityException, IllegalArgumentException,

            IllegalAccessException

    /*    */{

        /* 55 */

        m.setAccessible(true);

        /* 56 */

        return m;

        /*    */

    }


    public static Constructor setAccessible(Constructor c)

    /*    */
展开阅读全文