JavaBean_迭代_内省

  BeanInfo beanInfo = Introspector.getBeanInfo(pt1.getClass());
  PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
  Object rtyVal = null;
  for(PropertyDescriptor pd : pds){
   if(pd.getName().equals(propertyName)){
    Method methodGetX =pd.getReadMethod();
    rtyVal = methodGetX.invoke(pt1);
    break;
   }
  }
  
  return (PropertyDescriptor) rtyVal;
 }
}

你可能感兴趣的:(object)