@Test void shouldInvokeStaticMethod() { Object oldValue = new Object(); ReflectionsTestClass.changeStaticObject(oldValue); Method method = getMethod("changeStaticObject", Object.class); Object o = new Object(); Object result = ReflectionUtils.invokeMethod(method, null, o); assertThat(result, equalTo(oldValue)); assertThat(ReflectionsTestClass.changeStaticObject(null), equalTo(o)); }
public static Object invokeMethod(Method method, Object instance, Object... parameters) { method.setAccessible(true); try { return method.invoke(instance, parameters); } catch (InvocationTargetException | IllegalAccessException e) { throw new InjectorReflectionException( "Could not invoke method '" + method.getName() + "' for " + instance, e); } }
ReflectionUtils { public static Object invokeMethod(Method method, Object instance, Object... parameters) { method.setAccessible(true); try { return method.invoke(instance, parameters); } catch (InvocationTargetException | IllegalAccessException e) { throw new InjectorReflectionException( "Could not invoke method '" + method.getName() + "' for " + instance, e); } } }
ReflectionUtils { public static Object invokeMethod(Method method, Object instance, Object... parameters) { method.setAccessible(true); try { return method.invoke(instance, parameters); } catch (InvocationTargetException | IllegalAccessException e) { throw new InjectorReflectionException( "Could not invoke method '" + method.getName() + "' for " + instance, e); } } private  ReflectionUtils(); }
ReflectionUtils { public static Object invokeMethod(Method method, Object instance, Object... parameters) { method.setAccessible(true); try { return method.invoke(instance, parameters); } catch (InvocationTargetException | IllegalAccessException e) { throw new InjectorReflectionException( "Could not invoke method '" + method.getName() + "' for " + instance, e); } } private  ReflectionUtils(); static Object getFieldValue(Field field, Object instance); static void setField(Field field, Object instance, Object value); static Object invokeMethod(Method method, Object instance, Object... parameters); static T newInstance(Constructor<T> constructor, Object... parameters); @Nullable static Class<?> getGenericType(@Nullable Type genericType); @Nullable static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType); static Object toSuitableCollectionType(Class<?> rawType, Set<T> result); static Method[] safeGetDeclaredMethods(Class<?> clazz); static Field[] safeGetDeclaredFields(Class<?> clazz); }
ReflectionUtils { public static Object invokeMethod(Method method, Object instance, Object... parameters) { method.setAccessible(true); try { return method.invoke(instance, parameters); } catch (InvocationTargetException | IllegalAccessException e) { throw new InjectorReflectionException( "Could not invoke method '" + method.getName() + "' for " + instance, e); } } private  ReflectionUtils(); static Object getFieldValue(Field field, Object instance); static void setField(Field field, Object instance, Object value); static Object invokeMethod(Method method, Object instance, Object... parameters); static T newInstance(Constructor<T> constructor, Object... parameters); @Nullable static Class<?> getGenericType(@Nullable Type genericType); @Nullable static Class<?> getCollectionType(Class<?> mainType, @Nullable Type genericType); static Object toSuitableCollectionType(Class<?> rawType, Set<T> result); static Method[] safeGetDeclaredMethods(Class<?> clazz); static Field[] safeGetDeclaredFields(Class<?> clazz);  }