Import Java. beans. beaninfo; import Java. beans. introspector; import Java. beans. propertydescriptor; import Java. lang. reflect. field; import Java. lang. reflect. method;/*** use the introspection method to operate JavaBean */public class introspectortest {public static void main (string [] ARGs) throws exception {reflectpoint = new reflectpoint (3, 7 ); // call the traditional method class classz = reflectpoint in JavaBean. getclass (); field [] fields = classz. getdeclaredfields (); For (field: fields) {string name = "set" + field. getname (). touppercase (); Method method = classz. getmethod (name, Int. class); method. invoke (reflectpoint, 3);} system. out. println (reflectpoint); // call the an method in the internal mode string propertyname = "X"; // obtain the value of attribute x object retval = getproperty2 (reflectpoint, propertyname ); system. out. println (retval); // setproperty (reflectpoint, propertyname, 10) of attribute X; system. out. println (reflectpoint. getx ());} /*** set the attribute value * @ object to which the param OBJ attribute belongs * @ Param propertyname attribute name * @ Param propertyvalue attribute value */Private Static void setproperty (Object OBJ, string propertyname, object propertyvalue) throws exception {propertydescriptor Pd2 = new propertydescriptor (propertyname, obj. getclass (); Method setmethod = pd2.getwritemethod (); setmethod. invoke (OBJ, propertyvalue );} /*** get object property value * @ Param OBJ object * @ Param propertyname attribute name * @ return attribute value */private static object getproperty (Object OBJ, string propertyname) throws exception {propertydescriptor Pd = new propertydescriptor (propertyname, obj. getclass (); Method getmethod = PD. getreadmethod (); // get the get method object retval = getmethod. invoke (OBJ); Return retval ;} /*** Use Inner province to operate the JavaBean * @ Param OBJ attribute object * @ Param propertyname attribute name * @ return attribute value */private static object getproperty2 (Object OBJ, string propertyname) throws exception {object retval = NULL; beaninfo = introspector. getbeaninfo (obj. getclass (); propertydescriptor [] PDS = beaninfo. getpropertydescriptors (); For (propertydescriptor PD: PPS) {If (PD. getname (). equals (propertyname) {method getmethod = PD. getreadmethod (); retval = getmethod. invoke (OBJ); break ;}} return retval ;}}