Skip to content

Instantly share code, notes, and snippets.

@bbrother92
Created May 18, 2017 04:10
Show Gist options
  • Save bbrother92/55f19e7da6c88f343342fd6412cba236 to your computer and use it in GitHub Desktop.
Save bbrother92/55f19e7da6c88f343342fd6412cba236 to your computer and use it in GitHub Desktop.
#annotations
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