Skip to content

Instantly share code, notes, and snippets.

@13andrew13
Created April 12, 2017 17:32
Show Gist options
  • Save 13andrew13/e6c82b0ac05914dc0447dcc67a60994c to your computer and use it in GitHub Desktop.
Save 13andrew13/e6c82b0ac05914dc0447dcc67a60994c to your computer and use it in GitHub Desktop.
package Task1;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
/**
* Created by andrew on 04.04.17.
*/
public class Main {
public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
Class<?> cls = New.class;
Method[] methods = cls.getMethods();
for (Method method : methods) {
if(method.isAnnotationPresent(Test.class)){
Test t = method.getAnnotation(Test.class);
System.out.println(method.invoke(null,t.a(),t.b()));
}
}
}
}
class New{
@Test(a=2,b=5)
public static int test(int a, int b){
return a+b;
}
}
package Task1;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Created by andrew on 04.04.17.
*/
@Target(value = ElementType.METHOD)
@Retention(value = RetentionPolicy.RUNTIME)
public @interface Test {
int a();
int b();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment