Java tutorial
//package com.java2s; //License from project: Apache License import android.text.TextUtils; import java.lang.reflect.Field; public class Main { public static Object getField(String paramString, Object paramObject) throws Exception { if (TextUtils.isEmpty(paramString)) throw new RuntimeException("field name can not be empty"); if (paramObject == null) throw new RuntimeException("target object can not be null"); Field localField = paramObject.getClass().getDeclaredField(paramString); if (localField == null) throw new RuntimeException("target object: " + paramObject.getClass().getName() + " do not have this field: " + paramString); localField.setAccessible(true); return localField.get(paramObject); } }