Code example for Field

Methods: getInt

0
 
    public static int getIntFieldIfExists(Class<?> klass, String fieldName,
            Class<?> obj, int defaultVal) {
        try { 
            Field f = klass.getDeclaredField(fieldName);
            return f.getInt(obj);
        } catch (Exception e) {
            return defaultVal;
        } 
    } 
 
    private static boolean hasField(Class<?> klass, String fieldName) {
        try { 
            klass.getDeclaredField(fieldName);
            return true; 
        } catch (NoSuchFieldException e) {
            return false; 
        } 
    } 
 
    private static boolean hasMethod(String className, String methodName,