Code example for Method

Methods: invoke, isAccessible, setAccessible

0
  public Object getPropertyValue(Object target, String propertyName) {
    Method method = getGetter(propertyName);
    if (method == null && superClass != null) {
      method = superClass.getGetter(propertyName);
    } 
    if (!method.isAccessible())
      method.setAccessible(true);
    try { 
      return method.invoke(target);
    } catch (Exception e) {
      throw Throwables.propagate(e);
    } 
  } 
 
  /** 
   * Updates an instance to set a property to a given value 
   * This method is only intended to be used for simple properties 
   * 
   * @param target the instance to update 
   * @param propertyName the name of the property 
   * @param propertyValue the value to set in the property