Here you can find the source of invokeDeclaredMethodWithAnnotation(Class extends Annotation> annotationClass, Object target)
public static void invokeDeclaredMethodWithAnnotation(Class<? extends Annotation> annotationClass, Object target) throws InvocationTargetException, IllegalAccessException
//package com.java2s; /*// www . j a v a 2s . com * Copyright (c) 2011 - 2012. Elega9t Ltd. All rights reserved. * ELEGA9T PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.Copyright (c) 2011 - 2012. Elega9t Ltd. All rights reserved. */ import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { public static void invokeDeclaredMethodWithAnnotation(Class<? extends Annotation> annotationClass, Object target) throws InvocationTargetException, IllegalAccessException { Method[] declaredMethods = target.getClass().getDeclaredMethods(); for (Method declaredMethod : declaredMethods) { Annotation annotation = declaredMethod.getAnnotation(annotationClass); if (annotation != null) { invokeMethod(declaredMethod, target, new Object[] {}); } } } public static Object invokeMethod(Method method, Object target, Object[] parameters) throws InvocationTargetException, IllegalAccessException { method.setAccessible(true); return method.invoke(target, parameters); } }