Created
September 22, 2010 19:42
-
-
Save rschildmeijer/592370 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 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