Created
May 18, 2017 04:10
-
-
Save bbrother92/55f19e7da6c88f343342fd6412cba236 to your computer and use it in GitHub Desktop.
#annotations
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
import java.lang.annotation.*; | |
public class TestClass { | |
@About | |
public void mtd () throws NoSuchMethodException { | |
Class cl = TestClass.class; | |
Annotation an = cl.getMethod("mtd", null).getAnnotation(About.class); | |
System.out.println(cl.getMethod("mtd", null).getName()); | |
System.out.println(cl.getMethod("mtd", null).getReturnType()); | |
About ab= (About) an; | |
System.out.println(ab.info()); | |
} | |
} | |
@Target(ElementType.METHOD) | |
@Retention(RetentionPolicy.RUNTIME) | |
@interface About { | |
String info() default "default string"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment