1. 程式人生 > >遍歷實體類屬性

遍歷實體類屬性

main int lds true () cep declared person generate

public static void main(String[] args) throws IllegalArgumentException, IllegalAccessException {
// TODO Auto-generated method stub
Person p=new Person(3,"阿三");
for (Field field :p.getClass().getDeclaredFields()) {
field.setAccessible(true);
System.out.println(field.getName() + ":" +field.get(p));
}
}

遍歷實體類屬性