@Test public void testGetPropertySetterMethod() throws Exception { Method method = TestReflect.class.getMethod("setS", int.class); Assert.assertEquals(method, getPropertySetterMethod(TestReflect.class, "s", int.class)); method = TestReflect.class.getMethod("setB", boolean.class); Assert.assertEquals(method, getPropertySetterMethod(TestReflect.class, "b", boolean.class)); boolean error = false; try { getPropertySetterMethod(TestReflect.class, "xxx", String.class); } catch (Exception e) { error = true; } Assert.assertTrue(error); }
public static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz) { String methodName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1); try { return clazz.getMethod(methodName, propertyClazz); } catch (NoSuchMethodException e) { throw new SofaRpcRuntimeException("No setter method for " + clazz.getName() + "#" + property, e); } }
ReflectUtils { public static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz) { String methodName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1); try { return clazz.getMethod(methodName, propertyClazz); } catch (NoSuchMethodException e) { throw new SofaRpcRuntimeException("No setter method for " + clazz.getName() + "#" + property, e); } } }
ReflectUtils { public static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz) { String methodName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1); try { return clazz.getMethod(methodName, propertyClazz); } catch (NoSuchMethodException e) { throw new SofaRpcRuntimeException("No setter method for " + clazz.getName() + "#" + property, e); } }  }
ReflectUtils { public static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz) { String methodName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1); try { return clazz.getMethod(methodName, propertyClazz); } catch (NoSuchMethodException e) { throw new SofaRpcRuntimeException("No setter method for " + clazz.getName() + "#" + property, e); } }  static boolean isPrimitives(Class<?> clazz); static String getCodeBase(Class<?> cls); static Method getMethod(String clazzName, String methodName, String[] argsType); static Method getMethod(Class clazz, String methodName, Class... argsType); static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz); static Method getPropertyGetterMethod(Class clazz, String property); }
ReflectUtils { public static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz) { String methodName = "set" + property.substring(0, 1).toUpperCase() + property.substring(1); try { return clazz.getMethod(methodName, propertyClazz); } catch (NoSuchMethodException e) { throw new SofaRpcRuntimeException("No setter method for " + clazz.getName() + "#" + property, e); } }  static boolean isPrimitives(Class<?> clazz); static String getCodeBase(Class<?> cls); static Method getMethod(String clazzName, String methodName, String[] argsType); static Method getMethod(Class clazz, String methodName, Class... argsType); static Method getPropertySetterMethod(Class clazz, String property, Class propertyClazz); static Method getPropertyGetterMethod(Class clazz, String property);  }