set Constructor Accessible for reflection - Java Reflection

Java examples for Reflection:Constructor

Description

set Constructor Accessible for reflection

Demo Code


//package com.java2s;
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
    /*    */{//w w w .j  av a  2 s. c  om
        /* 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;
        /*    */
    }

    public static Method setAccessible(Method m)
    /*    */throws SecurityException, IllegalArgumentException,
            IllegalAccessException
    /*    */{
        /* 55 */
        m.setAccessible(true);
        /* 56 */
        return m;
        /*    */
    }

    public static Constructor setAccessible(Constructor c)
    /*    */throws SecurityException, IllegalArgumentException,
            IllegalAccessException
    /*    */{
        /* 63 */
        c.setAccessible(true);
        /* 64 */
        return c;
        /*    */
    }
}

Related Tutorials