Skip to content

Instantly share code, notes, and snippets.

@rschildmeijer
Created September 22, 2010 19:42
Show Gist options
  • Save rschildmeijer/592370 to your computer and use it in GitHub Desktop.
Save rschildmeijer/592370 to your computer and use it in GitHub Desktop.
package se.schildmeijer;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
public class Playground {
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@interface Asynchronous {
}
interface RequestHandler {
void get();
}
static class AsyncRequestHandler implements RequestHandler {
@Asynchronous
public void get() { }
}
static class SyncRequestHandler implements RequestHandler {
public void get() { }
}
public static void main(String[] args) throws SecurityException, NoSuchMethodException {
RequestHandler arh = new AsyncRequestHandler();
RequestHandler srh = new SyncRequestHandler();
Asynchronous c1 = arh.getClass().getDeclaredMethod("get", null).getAnnotation(Asynchronous.class);
Asynchronous c2 = srh.getClass().getDeclaredMethod("get", null).getAnnotation(Asynchronous.class);
if (c1 != null) {
System.out.println("asynch har @annotering");
}
if (c2 != null) {
System.out.println("synch har @annotering");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment