Here you can find the source of invokeGetter(Object target, Method getter)
Parameter | Description |
---|---|
target | object on which to call getter |
getter | method for some field |
public static Object invokeGetter(Object target, Method getter)
//package com.java2s; /*//from w w w .java 2 s . c o m * $Id$ * * Copyright 2006 University of Dundee. All rights reserved. * Use is subject to license terms supplied in LICENSE.txt */ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { /** * call getter and return object. * * @DEV.TODO there maybe be cases where an exception is ok * @param target * object on which to call getter * @param getter * method for some field * @return value stored in field */ public static Object invokeGetter(Object target, Method getter) { RuntimeException re = new RuntimeException("Error trying to get value: " + getter.toString()); Object result = null; try { result = getter.invoke(target, new Object[] {}); } catch (IllegalArgumentException e) { re.initCause(e); throw re; } catch (IllegalAccessException e) { re.initCause(e); throw re; } catch (InvocationTargetException e) { re.initCause(e); throw re; } return result; } }