java遍歷類的屬性和屬性值


public static void reflect(Object e) throws Exception {
	Class<? extends Object> cls = e.getClass();
	Field[] fields = cls.getDeclaredFields();
	for (int i = 0; i < fields.length; i++) {
		Field f = fields[i];
		f.setAccessible(true);
		System.out.println("屬性名:" + f.getName() + " 屬性值:" + f.get(e));
	}
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章