Exemple #1
0
 public Y call(X value) {
   Class cls = value.getClass();
   try {
     Field f = cls.getField(fieldName);
     return (Y) f.get(value);
   } catch (SecurityException e) {
     e.printStackTrace();
     throw new IllegalStateException();
   } catch (NoSuchFieldException e) {
     e.printStackTrace();
     throw new IllegalStateException();
   } catch (IllegalAccessException e) {
     e.printStackTrace();
     throw new IllegalStateException();
   }
 }
Exemple #2
0
  public Y call(X value) {
    Class cls = value.getClass();
    try {
      Method m = cls.getMethod(fieldName);
      return (Y) m.invoke(value);

    } catch (SecurityException e) {
      e.printStackTrace();
      throw new IllegalStateException();
    } catch (IllegalAccessException e) {
      e.printStackTrace();
      throw new IllegalStateException();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
      throw new IllegalStateException();
    } catch (NoSuchMethodException e) {
      e.printStackTrace();
      throw new IllegalStateException();
    }
  }