得到某个类的静态属性 java反射机制

/**
 * 得到某个类的静态属性 java反射机制
 * 
 * @param className
 * @param fieldName
 * @return
 * @throws Exception
 */
public Object getStaticProperty(String className, String fieldName)
		throws Exception {
	Class ownerClass = Class.forName(className);

	Field field = ownerClass.getField(fieldName);

	Object property = field.get(ownerClass);

	return property;
}

你可能感兴趣的:(Java相关)