//package com.nowjava;
import java.beans.BeanInfo;//NowJava.com - 时 代 Java 提 供
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
public class Main {
public static void main(String[] argv) throws Exception {
Object bean = "nowjava.com";
System.out.println(backupProp(bean));
}
public static Map<String, Object> backupProp(Object bean) {
Map<String, Object> result = new HashMap<>();
try {
BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
PropertyDescriptor[] propertyDescriptors = beanInfo
/**
来 自 时 代 J a v a - nowjava.com
**/
.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
String fieldName = propertyDescriptor.getName();
Method readMethod = propertyDescriptor.getReadMethod();
Object invoke = readMethod.invoke(bean, new Object[] {});
/**代码未完, 请加载全部代码(NowJava.com).**/
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。