Created
April 12, 2017 17:32
-
-
Save 13andrew13/e6c82b0ac05914dc0447dcc67a60994c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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