Java tutorial
//package com.java2s; import java.lang.reflect.Field; public class Main { public static int getRIdFromName(Class<?> cls, String filedName) { try { Field f = cls.getField(filedName); return Integer.parseInt(f.get(null).toString()); } catch (Exception e) { e.printStackTrace(); } return 0; } }