Java tutorial
//package com.java2s; //License from project: Apache License import java.lang.reflect.Field; public class Main { public static int getFieldIntSafely(Class clz, String fieldName, Object instance) { try { Field field = clz.getDeclaredField(fieldName); field.setAccessible(true); return field.getInt(instance); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } return 0; } }