/** * This is a shortcut for {@link #invokeSpecificMethod(Object, Class, String, Class...)}.{@link * InvocationTarget#withArguments(Object...)}. That is, it uses the types of the given arguments * to look up the method. This will only work if the types are exact matches for the parameter * types. * * @param <T> * @param instance * @param methodOwner * @param methodName * @param args * @return */ public static <T> T invokeMethod( Object instance, Class<?> methodOwner, String methodName, Object... args) { Class<?>[] types = new Class<?>[args.length]; for (int i = 0; i < args.length; i++) { types[i] = args[i].getClass(); } return Reflections.<T>invokeSpecificMethod(instance, methodOwner, methodName, types) .withArguments(args); }
public static <T> T invokeNoArgMethod(Object instance, Class<?> methodOwner, String methodName) { return Reflections.<T>invokeSpecificMethod(instance, methodOwner, methodName).withArguments(); }
public static <T> T getField(Object instance, Class<?> fieldOwner, String fieldname) { Preconditions.checkNotNull(instance, "instance is null"); Preconditions.checkArgument( fieldOwner.isInstance(instance), "%s is not a %s", instance, fieldOwner); return Reflections.<T>getFieldInternal(instance, fieldOwner, fieldname); }
public static <T> T getStaticFieldValue(Class<?> fieldOwner, String fieldname) { return Reflections.<T>getFieldInternal(null, fieldOwner, fieldname); }