All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jnr.posix.util.FieldAccess Maven / Gradle / Ivy

There is a newer version: 0.3.1
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jnr.posix.util;

import java.lang.reflect.Field;

/**
 *
 * @author nicksieger
 */
public class FieldAccess {
    public static Field getProtectedField(Class klass, String fieldName) {
        Field field = null;
        try {
            field = klass.getDeclaredField(fieldName);
            field.setAccessible(true);
        } catch (Exception e) {
        }
        return field;
    }
    public static Object getProtectedFieldValue(Class klass, String fieldName, Object instance) {
        try {
            Field f = getProtectedField(klass, fieldName);
            return f.get(instance);
        } catch (Exception e) {
            throw new IllegalArgumentException(e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy