Code example for Field

Methods: setAccessiblegetBoolean

0
    static Field getField(Object obj, String fieldName)
            throws SecurityException, NoSuchFieldException 
    { 
        Field field = obj.getClass().getDeclaredField(fieldName);
 
        field.setAccessible(true);
        return field;
    } 
 
    /** 
     * Retrieves the value of an integer field regardless to it's access 
     * modifier.   
     * @param obj object to retrieve the field value from 
     * @param fieldName name of the field 
     * @return retrieved value of the field 
     * @throws SecurityException is such operation is prohibited by system 
     * security manager 
     * @throws NoSuchFieldException if the filed with such name has not been 
     * found 
     */ 
    static int getIntField(Object obj, String fieldName)
            throws SecurityException, NoSuchFieldException, 
                   IllegalArgumentException 
    { 
        Field field = getField(obj, fieldName);
        int n = -1;
 
        try { 
            n = field.getInt(obj);
        } 
        catch (IllegalAccessException e) {
            // FIXME 
            e.printStackTrace();
        } 
        return n;
    } 
 
    /** 
     * Retrieves the value of a boolean field regardless to it's access 
     * modifier.   
     * @param obj object to retrieve the field value from 
     * @param fieldName name of the field 
     * @return retrieved value of the field 
     * @throws SecurityException is such operation is prohibited by system 
     * security manager 
     * @throws NoSuchFieldException if the filed with such name has not been 
     * found 
     */ 
    static boolean getBoolField(Object obj, String fieldName)
            throws SecurityException, NoSuchFieldException, 
                   IllegalArgumentException 
    { 
        Field field = getField(obj, fieldName);
        boolean  b = false;
 
        try { 
            b = field.getBoolean(obj);
        } 
        catch (IllegalAccessException e) {
            // FIXME 
            e.printStackTrace();
        } 
Connect your IDE to all the code out there  Get Codota for Java