JAVA 简单的反射实现

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011508145/article/details/79745765
Class bean1 = Class.forName(className);

java.beans.BeanInfo info = java.beans.Introspector.getBeanInfo(bean1);

java.beans.PropertyDescriptor pd[] = info.getPropertyDescriptors();

for (int k = 0; k < pd.length; k++) 
{
 if (pd[k].getName().equalsIgnoreCase(name)) 
 {
   Method mSet = null; 
   mSet = pd[k].getWriteMethod(); 
   mSet.invoke(beanMap.get(id), beanMap.get(ref)); 
  } 
}

 

猜你喜欢

转载自blog.csdn.net/u011508145/article/details/79745765
今日推荐