java的反射
遍历对象的字段
public static void main(String[] args) throws Exception{ DataSource dataSource = new DataSource(); reflect(dataSource); } public static<T> void reflect(T e) throws Exception{ Class 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)); } }